Monday, 8 February 2016

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
view raw gistfile1.txt hosted with ❤ by GitHub

No comments:

Post a Comment