Old Russian measure of length: Difference between revisions
Content added Content deleted
No edit summary |
(→{{header|Ruby}}: Add Ruby) |
||
Line 2,208: | Line 2,208: | ||
centimeter : 10000 |
centimeter : 10000 |
||
meter : 100 |
meter : 100 |
||
</pre> |
|||
=={{header|Ruby}}== |
|||
<lang ruby>module Distances |
|||
RATIOS = |
|||
{arshin: 0.7112, centimeter: 0.01, diuym: 0.0254, |
|||
fut: 0.3048, kilometer: 1000.0, liniya: 0.00254, |
|||
meter: 1.0, milia: 7467.6, piad: 0.1778, |
|||
sazhen: 2.1336, tochka: 0.000254, vershok: 0.04445, |
|||
versta: 1066.8} |
|||
def self.method_missing(meth, arg) |
|||
from, to = meth.to_s.split("2").map(&:to_sym) |
|||
raise NoMethodError, meth if ([from,to]-RATIOS.keys).size > 0 |
|||
return arg if from == to |
|||
(RATIOS[from] / RATIOS[to]) * arg |
|||
end |
|||
end |
|||
p Distances.meter2centimeter(3) |
|||
p Distances.arshin2meter(1) |
|||
p Distances.versta2kilometer(20) # en Hoeperdepoep zat op de stoep |
|||
# 13*13 = 169 methods supported, but not: |
|||
p Distances.mile2piad(1) |
|||
</lang> |
|||
{{out}} |
|||
<pre>300.0 |
|||
0.7112 |
|||
21.336 |
|||
distances.rb:12:in `method_missing': mile2piad (NoMethodError) |
|||
from distances.rb:22:in `<main>' |
|||
</pre> |
</pre> |
||