Within the Class I define things which I would expect to be Global.
Both the matrix and the reference to class are not seen in the method
calculate, as they fall outside of the method declaration. How do I
make them visible, so they can remain where they are( Yes, I could pass
the matrix variable - e.g., calculate(m)- but is there another way to do
this?) I don't think I could pass subr in this manner.
Class Subroutines
#some subroutines listed here
def altitude(abs_psr_inhg)
#stuff
end
end
Class Ballistics
require 'Matrix'
m = Matrix[[1,2,3],[4,5,6]]
subr = Subroutines.new
def calculate
puts m
alt = subr.altitude(abs_psr_inhg)
end
end
···
--
Posted via http://www.ruby-forum.com/.
You could use instance variables. By the way, class is lowecase:
class Subroutines
def altitude(abs_psr_inhg)
puts "altitude"
end
end
class Ballistics
require 'Matrix'
def initialize
@m = Matrix[[1,2,3],[4,5,6]]
@subr = Subroutines.new
end
def calculate
puts @m
alt = @subr.altitude(@m)
end
end
b = Ballistics.new
b.calculate
Jesus.
···
On Wed, Jan 26, 2011 at 12:36 AM, Jim Carter <jcarter@leupold.com> wrote:
Within the Class I define things which I would expect to be Global.
Both the matrix and the reference to class are not seen in the method
calculate, as they fall outside of the method declaration. How do I
make them visible, so they can remain where they are( Yes, I could pass
the matrix variable - e.g., calculate(m)- but is there another way to do
this?) I don't think I could pass subr in this manner.
Class Subroutines
#some subroutines listed here
def altitude(abs_psr_inhg)
#stuff
end
end
Class Ballistics
require 'Matrix'
m = Matrix[[1,2,3],[4,5,6]]
subr = Subroutines.new
def calculate
puts m
alt = subr\.altitude\(abs\_psr\_inhg\)
end
end