Skip to content

Instantly share code, notes, and snippets.

@sfcgeorge
Created March 17, 2016 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sfcgeorge/54d3497e1506881b221f to your computer and use it in GitHub Desktop.
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
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