Skip to content

Instantly share code, notes, and snippets.

@aoitaku
Created October 31, 2014 17:19
Show Gist options
  • Save aoitaku/beab0c231cf4e0f7b478 to your computer and use it in GitHub Desktop.
Save aoitaku/beab0c231cf4e0f7b478 to your computer and use it in GitHub Desktop.
ヒアドキュメントは式
def event_handler(*names)
names.each do |name|
class_eval <<-EOS
def on_#{name}(*args)
event_handlers[:#{name}] and event_handlers[:#{name}].(*args)
end
EOS
end
end
# 実はこう書ける
def event_handler(*names) names.each {|name| class_eval(<<-EOS) } end
def on_#{name}(*args)
event_handlers[:#{name}] and event_handlers[:#{name}].(*args)
end
EOS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment