Answer the question
In order to leave comments, you need to log in
What to do in Ruby (Rails) if a class method is not visible inside some block?
Let's say we have a class:
class MyClass
def a_method
...
end
def b_method
Technology.new do |t|
a_method()
end
end
end
Answer the question
In order to leave comments, you need to log in
codepad.org/HcmmPAgg
# Technology
class Technology
attr_accessor :val
def initialize
@val = 42
yield self
end
end
# MyClass2
class MyClass
# @param [Integer] val
# @return [NilClass]
def a_method(val)
puts val
end
# @return [NilClass]
def b_method
Technology.new do |technology|
a_method technology.val
end
end
end
my_class = MyClass.new
my_class.b_method # => 42
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question