Skip to content

Instantly share code, notes, and snippets.

@msroot
Created February 8, 2016 10:35
Show Gist options
  • Select an option

  • Save msroot/6c0ecb0421c626d5f5f1 to your computer and use it in GitHub Desktop.

Select an option

Save msroot/6c0ecb0421c626d5f5f1 to your computer and use it in GitHub Desktop.
ruby method chain from string
# key = "method.another_method"
#user.method.another_method = :foo
#amazing method chain :D
arry = key.split('.')
last = arry.pop
arry.inject(user, :send).send "#{last}=".to_sym, value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment