Skip to content

Instantly share code, notes, and snippets.

@rsl
Forked from anonymous/gist:106983
Created May 5, 2009 14:16
Show Gist options
  • Save rsl/106986 to your computer and use it in GitHub Desktop.
Save rsl/106986 to your computer and use it in GitHub Desktop.
Units = { :dollar_per_ffe => { :symbol => "$/ffe", :si_factor=>1.0 },
:dollar_per_ton => { :symbol => "$/T", :si_factor=>1.0e-3 }
}
Attribute_Units = { :default_transshipment_cost => :dollar_per_ffe,
:bunker_cost => :dollar_per_ton
}
Attribute_Units.each do |name, value|
define_method(name) do
read_attribute(name) / Units[Attribute_Units[name]][:si_factor]
end
define_method("#{name}=) do |assigned_value|
write_attribute(name, assigned_value * Units[Attribute_Units[name]][:si_factor])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment