这个十进制表示法在ruby中是什么意思?
电话号码如下:这个十进制表示法在ruby中是什么意思?,ruby,Ruby,电话号码如下: #<BigDecimal:9829250,'0.202499E4',18(27)> # 如果我打印它,它是:2024.99。9829250(可能是内存地址?)和18(27)的含义是什么?不需要猜测我们什么时候有 BigDecimal#inspect() 以逗号分隔的值字符串形式返回有关该值的调试信息,该值位于带前导#的尖括号中: BigDecimal.new(“1234.5678”)。检查 #=> "#" 第一部分是地址,第二部分是字符串形式的值,最后一部分ss
#<BigDecimal:9829250,'0.202499E4',18(27)>
#
如果我打印它,它是:
2024.99
。9829250
(可能是内存地址?)和18(27)
的含义是什么?不需要猜测我们什么时候有
BigDecimal#inspect()
以逗号分隔的值字符串形式返回有关该值的调试信息,该值位于带前导#的尖括号中:
BigDecimal.new(“1234.5678”)。检查
#=> "#"
第一部分是地址,第二部分是字符串形式的值,最后一部分ss(mm)分别是当前有效位数和最大有效位数
如果安装了源代码,可以在那里查看。以下信息适用于RVM的本地用户安装 作为@Dogbert答案的替代方法,您还可以查看源文件:
cd ~/.rvm/src/ruby-2.2.4/ext/bigdecimal/
如果查看第2034行附近的bigdecimal.c
,您将看到以下文档:
/* Returns debugging information about the value as a string of comma-separated
* values in angle brackets with a leading #:
*
* BigDecimal.new("1234.5678").inspect ->
* "#<BigDecimal:b7ea1130,'0.12345678E4',8(12)>"
*
* The first part is the address, the second is the value as a string, and
* the final part ss(mm) is the current number of significant digits and the
* maximum number of significant digits, respectively.
*/
/*以逗号分隔的字符串形式返回有关该值的调试信息
*尖括号中带前导#的值:
*
*BigDecimal.new(“1234.5678”)。检查->
* "#"
*
*第一部分是地址,第二部分是字符串形式的值,以及
*最后一部分ss(mm)是当前有效位数和
*有效位数的最大值。
*/
欢迎来到堆栈溢出。请阅读“”及其链接页和“”。这个问题经常被问到,有许多页面描述了inspect
及其输出。此外,Ruby教程和书籍很早就涵盖了inspect
,因此应该很容易找到。注意:给出的路径只会帮助那些使用RVM的人。根据您的操作系统以及正在使用的RVM或rbenv
等工具,路径可能会有很大的不同。在许多Linux发行版上,除非您安装了Ruby的“开发”版本,否则您甚至不会安装这些文件,而且在某些情况下,即使是这样,您也需要从源代码处安装。使用ri BigDecimal#inspect
或ri BigDecimal.inspect
,从命令行进行安装会更简单、更不容易出错。@theTinMan我同意,您的命令给出了一个错误“对BigDecimal#inspect一无所知”。我只是想指出,如果你已经安装了源代码,你可以查看它,作为替代。
/* Returns debugging information about the value as a string of comma-separated
* values in angle brackets with a leading #:
*
* BigDecimal.new("1234.5678").inspect ->
* "#<BigDecimal:b7ea1130,'0.12345678E4',8(12)>"
*
* The first part is the address, the second is the value as a string, and
* the final part ss(mm) is the current number of significant digits and the
* maximum number of significant digits, respectively.
*/