百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
A

alchemist

> 编程语言
开源

一个科学转换库。

156 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

一个科学转换库。

Alchemist

Doing conversions for you so you don’t have to google them and making code more readable.

Having code that looks like this is meaningless

ruby
meters = 8 * 1609.344

You could add comments

ruby
meters = 8 * 1609.344 # converting miles to meters

But why not have this!

ruby
8.miles.to.meters

You can even perform mathematical operations

ruby
10.kilometers + 1.mile # 11.609344 kilometers

Handling bytes now works according to the JEDEC memory standard

ruby
1.kb.to.b.to_f == 1024.0

Converting distance of arc length on Earth to an (approximate) corresponding spherical geometry angle can be done with

ruby
require 'alchemist/geospatial'
1.mile.geospatial.to.degree == 0.014457066992474555

To switch to the IEC memory standard, force SI units with

ruby
Alchemist.config.use_si = true

To see all the units alchemist has built in conversion for, check out the units file

You may also register your own units

ruby
Alchemist.register(:distance, [:beard_second, :beard_seconds], 5.angstroms)

Installation

gem install alchemist

Setup

In order for methods like 1.meter to work, you'll either need to setup Alchemist yourself:

ruby
Alchemist.setup # This will load every category of measurement

if you only want to use one category for conversions you can load it individually:

ruby
Alchemist.setup('distance') # This will load only distance

Rails

Setup

It is suggested that you add your Alchemist.setup call to config/initializers/alchemist.rb and then restart your rails server.

Rails Warning

Rails adds some methods like bytes to Numeric so it's highly recommended that instead of trying to call bytes on a numeric, you should use the measure method:

ruby
Alchemist.measure(10, :bytes)

License

Alchemist is licensed under the MIT license as specified in the gemspec

Issues· 5 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言