Skip to content

Instantly share code, notes, and snippets.

@mark
Created April 3, 2012 17:49
Show Gist options
  • Save mark/2294093 to your computer and use it in GitHub Desktop.
Save mark/2294093 to your computer and use it in GitHub Desktop.
Send an array of method names
class Object
def send_key_path(key_path)
key_path.inject(self) { |current, method| current.send(method) }
end
end
class Foo
def bar
Bar.new
end
end
class Bar
def baz
Baz.new
end
end
class Baz
def quux
"quux"
end
end
obj = Foo.new
puts obj.send_key_path "bar.baz.quux".split('.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment