Skip to content

Instantly share code, notes, and snippets.

@JeffCohen
Created June 13, 2012 16:21
Show Gist options
  • Save JeffCohen/2925061 to your computer and use it in GitHub Desktop.
Save JeffCohen/2925061 to your computer and use it in GitHub Desktop.
Dynamic Ruby
# s = "Can't believe Los Angeles won the Stanley Cup"
#
# a = ["downcase", "reverse", "upcase"]
#
# a.each do |m|
# puts s.send(m)
# end
class Team
def method_missing(m, *args)
return "Chicago"
end
end
t = Team.new
t.city = "Chicago"
puts t.city #=> Chicago
# puts s.downcase
# puts s.reverse
# puts s.upcase
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment