ruby - Binding within a block -
i'd use block within method initialize
. code:
class settlement attr_reader :url, :parameters def initialize(&block) instance_eval block.call end def parameters(x) ; @parameters = x; end def url(x) ; @url = x; end end settlement = settlement.new url "https://xxxxx" parameters("ffff") end
i got error message below:
nomethoderror - undefined method parameters
any ideas?
when call instance_eval block.call
block.call
evaluated before instance_eval
called. means block called without instance binding.
this should work:
def initialize(&block) instance_eval &block end
Comments
Post a Comment