Created
March 30, 2016 11:54
-
-
Save karloku/30f6d7f98d99a67b1260ea057f16d5db to your computer and use it in GitHub Desktop.
Using ES6 style {a, b, c} hash construct in Ruby ref: http://qiita.com/karloku/items/0a3c8ed3e39518de5b90
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
var year = 2016; | |
var month = 3; | |
var day = 30; | |
var theDate = { year, month, day }; |
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
def HandyHash(&list_block) | |
variables = yield.map(&:to_s) | |
Hash[ | |
variables.map do |variable| | |
[variable.to_sym, list_block.binding.local_variable_get(variable)] | |
end | |
] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment