Created
March 17, 2016 10:59
-
-
Save sfcgeorge/54d3497e1506881b221f to your computer and use it in GitHub Desktop.
Passing a lot of variables into a mailer that I want to access from the view, so decided to dynamically set the instance variables from opts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DynamicIvars | |
def greet(**options) | |
options.each { |k, v| instance_variable_set :"@#{k}", v } | |
p @hello | |
end | |
end | |
DynamicIvars.new.greet hello: "world" | |
# => "world" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment