Created
December 31, 2021 00:02
-
-
Save jaredcwhite/e6a59e5908ddd761d33afebd8fd34fda to your computer and use it in GitHub Desktop.
A Ruby equivalent to JavaScript's Object.assign
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
Object.class_eval do | |
def self.assign(obj, options={}) | |
options.each do |k, v| | |
obj.send("#{k}=", v) | |
end | |
obj | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment