money rails - How could I remove duplicated sections in Ruby DSL -


my current config format seems redundant. how convert next expected config format?

my expected config is:

moneyrails.configure |config|      register_currency("twd", 100)     register_currency("usd", 100)     .... end 

my current config is:

moneyrails.configure |config|    config.register_currency = {     :priority            => 1,     :iso_code            => "twd",     :name                => "twd",     :symbol              => "nt$ ",     :symbol_first        => true,     :subunit             => "subcent",     :subunit_to_unit     => 100,     :thousands_separator => ",",     :decimal_mark        => "."   }    config.register_currency = {     :priority            => 1,     :iso_code            => "usd",     :name                => "usd",     :symbol              => "$ ",     :symbol_first        => true,     :subunit             => "subcent",     :subunit_to_unit     => 100,     :thousands_separator => ",",     :decimal_mark        => "."   }    config.register_currency = {     :priority            => 1,     :iso_code            => "sgd",     :name                => "sgd",     :symbol              => "$ ",     :symbol_first        => true,     :subunit             => "subcent",     :subunit_to_unit     => 100,     :thousands_separator => ",",     :decimal_mark        => "."   }    config.register_currency = {     :priority            => 1,     :iso_code            => "thb",     :name                => "thb",     :symbol              => "$ ",     :symbol_first        => true,     :subunit             => "subcent",     :subunit_to_unit     => 100,     :thousands_separator => ",",     :decimal_mark        => "."   }    config.register_currency = {     :priority            => 1,     :iso_code            => "aud",     :name                => "aud",     :symbol              => "$ ",     :symbol_first        => true,     :subunit             => "subcent",     :subunit_to_unit     => 100,     :thousands_separator => ",",     :decimal_mark        => "."   }    config.register_currency = {     :priority            => 1,     :iso_code            => "krw",     :name                => "krw",     :symbol              => "$ ",     :symbol_first        => true,     :subunit             => "subcent",     :subunit_to_unit     => 100,     :thousands_separator => ",",     :decimal_mark        => "."   }    ...  end 

default_options = {     :priority            => 1,     :iso_code            => 'usd',     :name                => 'usd',     :symbol              => "$ ",     :symbol_first        => true,     :subunit             => "subcent",     :subunit_to_unit     => 100,     :thousands_separator => ",",     :decimal_mark        => "." }  moneyrails.configure |config|   config.register_currency = default_options   config.register_currency = default_options.merge(name: 'twd', iso_code: 'twd', symbol: 'nt$')   config.register_currency = default_options.merge(name: 'thb', iso_code: 'thb')   config.register_currency = default_options.merge(name: 'sgd') end 

the merge method merges 2 hash instances , returns hash object. if second hash object has keys matching first second hash's key => value replaces/overrides former one.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -