大佬教程收集整理的这篇文章主要介绍了在Ruby中转换物理单位(千克,磅)的图书馆?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
require 'alchemist' Alchemist.setup 8.miles.to.meters 10.kilometers + 1.mile # 11.609344 kilometers
> measurement@H_801_7@
这一次出现过时了,最后一次提交是5年前,对我来说似乎没有运行在1.9.3.@H_801_7@
include Measurement::Length Inch.new(12).to_centimeters # => #<Measurement::Length::Centimeter:0x173c2b4 @units=30.48>
> Phys-Units@H_801_7@
require "phys/units" Q = Phys::Quantity U = Phys::Unit Q[1.23,'km'] + Q[4.56,'m'] #=> Phys::QuantitY[1.23456,'km'] Q[123,'mile'] / Q[2,'hr'] #=> Phys::QuantitY[61,'mile/hr'] Q[61,'miles/hr'].want('m/s') #=> Phys::QuantitY[27.26944,'m/s'] Q[1.0,'are'] == Q[10,'m']**2 #=> true
请注意,这个说明README中没有生产就绪.@H_801_7@
require 'quantity/all' 1.meter #=> 1 meter 1.meter.to_feet #=> 3.28083... foot c = 299792458.meters / 1.second #=> 299792458 meter/second newton = 1.meter * 1.kilogram / 1.second**2 #=> 1 meter*kilogram/second^2 newton.to_feet #=> 3.28083989501312 foot*kilogram/second^2 newton.convert(:feet) #=> 3.28083989501312 foot*kilogram/second^2 jerk_newton = newton / 1.second #=> 1 meter*kilogram/second^3 jerk_newton * 1.second == newton #=> true
见Boris Stitnickey’s answer.
> ruby-measurement@H_801_7@
require 'ruby-measurement' measurement = Measurement.parse('3 feet') # => 3.0 ft. measurement.convert_to(:yards) # => 1.0 yd. measurement.convert_to(:in) # => 36.0 in. measurement.convert_to(:inches) # => 36.0 in. measurement1 = Measurement.parse('3 feet') # => 3.0 ft. measurement2 = Measurement.parse('6 inch') # => 6.0 in. measurement1 + measurement2 # => 3.5 ft.
> ruby-units@H_801_7@
require 'ruby-units' unit = Unit("mm") # unit only (defaults to a scalar of 1) unit = Unit("1 mm") # create a simple unit unit = Unit("1 kg*m^2/s^2") # complex unit unit1 =~ unit2 # true if units are compatible unit1.compatible?(unit2) # true if units are compatible unit1 = unit >> "ft" # convert to 'feet' unit3 = unit1 + unit2 # resulTing object will have the units of unit1 unit1 === unit2 # true if units and quantity are the same,even if 'equivalent' by <=> unit.convert_to('ft') # convert (unit1 + unit2).convert_to('ft') # converts result to 'ft'
> Units for Ruby@H_801_7@
require 'units' three_meters = 3.meters two_meters = 2.m one_inch = 1.inch 3.meters.to_inches # => 118.1103 inch 10.inches.to_mm # => 254.0 millimeter
require 'unitwise/ext' 1.yard == (1.foot * 3) # => true 1.quart < 1.liter # => true 2.meter + 3.inch - 1.yard # => <Unitwise::Measurement 1.1618 meter> 1.convert_to('kg.m2/s2') == 1.joule # => true (20.kg * 9.8.convert_to('m/s2')).to_pound_force # => <Unitwise::Measurement 44.06255284754326 pound_force> (300.horsepower * 60.second).to_calorie # => <Unitwise::Measurement 3208077.8414151203 calorie>
像另一张海报,我有麻烦让这个工作.但是,您可以看到Jörg W Mittag’s answer的使用.@H_801_7@
以上是大佬教程为你收集整理的在Ruby中转换物理单位(千克,磅)的图书馆?全部内容,希望文章能够帮你解决在Ruby中转换物理单位(千克,磅)的图书馆?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。