简体   繁体   English

如何找出用 Ruby 打包的库的版本,例如 json?

[英]How can I find out the version of a library that is packaged with Ruby, e.g. json?

Some Ruby functionality packaged with the Ruby distribution (and not needing to be installed as gems explicitly or via bundler).一些 Ruby 功能打包在 Ruby 发行版中(不需要作为 gem 显式安装或通过捆绑器安装)。 JSON is one example ( require 'json' ). JSON 就是一个例子( require 'json' )。 It can be required in Ruby code but doesn't require gem installation.它在 Ruby 代码中可能是必需的,但不需要 gem 安装。

Yet JSON is a gem on Github, at https://github.com/flori/json .然而,JSON 是 Github 上的瑰宝,网址为https://github.com/flori/json

So how can I know which version of that gem I'm getting when I require 'json' in my code?那么,当我的代码中需要 'json' 时,我怎么知道我得到的是哪个版本的 gem?

Alternatively many ruby gems specify their version in a constant.或者,许多 ruby​​ gem 在常量中指定它们的版本。

You can utilize this to determine the version you are using in code or in console as well eg您可以利用它来确定您在代码或控制台中使用的版本,例如

require 'json'
JSON.constants.grep(/VERSION/)
#=>[:VERSION, :VERSION_ARRAY, :VERSION_MAJOR, :VERSION_MINOR, :VERSION_BUILD]
JSON::VERSION
#=> 2.5.1
require 'bundler'
Bundler.constants.grep(/VERSION/)
#=> [:VERSION]
Bundler::VERSION
#=> 2.2.3

You can find the Ruby home directory, and search below it for a directory of the appropriate name, and then inspect its version.rb file.您可以找到 Ruby 主目录,并在其下方搜索具有适当名称的目录,然后检查其version.rb文件。 For example, with rvm-managed rubies, I can do this (on a Posix-complaint system such as Linux or Mac OS):例如,使用 rvm 管理的 rubies,我可以这样做(在 Posix-complaint 系统上,例如 Linux 或 Mac OS):

$ cd $(which ruby)/../..; pwd
/Users/keith.bennett/.rvm/rubies/ruby-3.0.1

$find . -type d -name '*json*'
./lib/ruby/3.0.0/psych/json
./lib/ruby/3.0.0/json
./lib/ruby/3.0.0/rdoc/generator/template/json_index
./lib/ruby/3.0.0/x86_64-darwin19/json
./lib/ruby/gems/3.0.0/gems/json-2.5.1
./lib/ruby/gems/3.0.0/gems/rbs-1.0.4/stdlib/json

I can cat ./lib/ruby/3.0.0/json/version.rb | grep 'VERSION '我可以cat ./lib/ruby/3.0.0/json/version.rb | grep 'VERSION ' cat ./lib/ruby/3.0.0/json/version.rb | grep 'VERSION ' (include the space after "VERSION"), and I get: cat ./lib/ruby/3.0.0/json/version.rb | grep 'VERSION ' (包括“VERSION”之后的空格),我得到:

  VERSION         = '2.5.1'

..which is also the version of the gem in the gems directory included in the listing above. ..这也是上面列表中包含的gems目录中的 gem 版本。

So I can see that 2.5.1 is my JSON version.所以我可以看到 2.5.1 是我的 JSON 版本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在c#中解析JSON字符串获取错误无法反序列化当前的JSON对象(例如{“name”:“value”}) - How can i parse JSON string in c# Get error Cannot deserialize the current JSON object (e.g. {“name”:“value”}) 如何操作Swift中的嵌套字典,例如JSON数据? - How do I manipulate nested dictionaries in Swift, e.g. JSON data? 如何创建简单的 JSON API,例如使用 Jetty? - How to create simple JSON API, e.g. with Jetty? 无法反序列化当前的JSON数组(例如[1,2,3])。 C#,无法找出错误 - Cannot deserialize the current JSON array (e.g. [1,2,3]). C#, cant figure the error out 如何使用字段名称的无效字符来解析Json? 例如,使用Newtonsoft {{“文件/文件夹”:“ /Shared/Salesforce/asdf.txt”}? - How do I parse Json with an invalid character for a field name? e.g. { “file/folder”: “/Shared/Salesforce/asdf.txt” } with Newtonsoft? json2html如何处理json键中的特殊字符(例如@) - json2html how to deal with special characters (e.g. @) in json keys 如何从Json.NET序列化的JSON恢复循环引用(例如“ $ id”)? - How to restore circular references (e.g. “$id”) from Json.NET-serialized JSON? 无法将当前的JSON数组(例如[1,2,3])反序列化为类型……我在做什么错? - Cannot deserialize the current JSON array (e.g. [1,2,3]) into type… what am I doing wrong? 如何避免 node_modules 测试,例如 json-schema-traverse? - How to avoid node_modules tests, e.g. json-schema-traverse? 如何使用SuperObject序列化包含点(例如IP地址)的JSON密钥? - How to serialize JSON key containing dots (like e.g. IP address) with SuperObject?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM