Más contenido relacionado
La actualidad más candente (9)
method_missingの紹介(2013 3Qカジュアル勉強会資料)
- 9. class Man
def method_missing(name , *args)
puts "#{name} method exec"
puts args.join('==')
end
end
@man = Man.new
@man.hogehoge('one' , 'two' , 'three')
$ hogehoge method exec
$ one==two==three
- 10. class Man
def exec(name , args)
puts "#{name} Call"
puts "http://hogehoge/api/#{name}/#{args[0] || 'test'} exec"
end
def method_missing(name , *args)
puts "method missing exec"
exec name , args
end
end
$ @man = Man.new
$ @man.ugo
method missing exec
ugo Call
http://hogehoge/api/ugo/ exec