Skip to content

Instantly share code, notes, and snippets.

View nashirox's full-sized avatar
🏠
Working from home

Daisuke Nashiro nashirox

🏠
Working from home
View GitHub Profile
@nashirox
nashirox / conditional_hash.rb
Last active December 3, 2021 06:18
Samples to building an hash key\value pairs in a conditional way.
# case1
Hash.new.tap do |hash|
hash[:key1] = value1 if condition_1
hash[:key2] = value2 if condition_2
end
# case2
hash = {}
hash[:key1] = value1
hash[:key2] = value2 if condition_2