Merge in Ruby works like this:
> options = { buy: true }
=> {:buy=>true}
> options.merge! when: :tomorrow
=> {:buy=>true, :when=>:tomorrow}
> options
=> {:buy=>true, :when=>:tomorrow}
> options.merge! buy: false
=> {:buy=>false, :when=>:tomorrow}
> options
=> {:buy=>false, :when=>:tomorrow}
> options.merge! :when => :today
=> {:buy=>false, :when=>:today}
Reverse Merge in Rails works like this:
rails c
Loading development environment (Rails 5.0.0.beta3)
> options = { buy: true }
=> {:buy=>true}
> options.reverse_merge! when: :tomorrow
=> {:buy=>true, :when=>:tomorrow}
> options
=> {:buy=>true, :when=>:tomorrow}
> options.reverse_merge! buy: false
=> {:buy=>true, :when=>:tomorrow}
> options
=> {:buy=>true, :when=>:tomorrow}
> options.reverse_merge! :when => :today
=> {:buy=>true, :when=>:tomorrow}
No comments:
Post a Comment