vendredi 27 juin 2014

Ruby : using block witih initilize


Vote count:

0




I'd like to use block in ruby within the initialize method .



class Settlement

attr_reader :url, :parameters

def initialize(&block)
instance_eval block.call
end

#initialize用
def parameters(x) ; @parameters = x; end
def url(x) ; @url = x; end

end

settlement = Settlement.new do
url "https://xxxxx"
parameters("ffff")
end


With this code, i got the below error message



NoMethodError - undefined method parameters



Any ideas ?


Thank you



asked 43 secs ago

johann

153





Aucun commentaire:

Enregistrer un commentaire