`
jsntghf
  • 浏览: 2483026 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

为什么ruby中的nil.object_id等于4

阅读更多

原因是因为nil是一个固定的object,在$rubyhome\lib\1.8\i386-mswin32中的ruby.h头文件里面有如下特殊对象的构造。

 

/* special contants - i.e. non-zero and non-fixnum constants */
#define Qfalse ((VALUE)0)
#define Qtrue  ((VALUE)2)
#define Qnil   ((VALUE)4)
#define Qundef ((VALUE)6) /* undefined value for placeholder */

 

在rails的activesupport里面,也有一个whiny_nil.rb的类有些相关的说明。

分享到:
评论

相关推荐

    to_nil:to_nil 宝石

    安装将此行添加到应用程序的 Gemfile 中: gem 'mr_to_nil' 然后执行: $ bundle或者自己安装: $ gem install mr_to_nil用法 [ :random , :array ] . to_nil # nil31337 . to_nil # nil"Yet another shitty gem" . ...

    cocos2dx_LUA_RichLabel

    RichLabel._fontName = nil RichLabel._fontSize = nil RichLabel._fontColor = nil RichLabel._containLayer = nil --装载layer RichLabel._dimensions = nil RichLabel._spriteArray = {} --精灵数组 RichLabel._...

    boolean2:Boolean2 是一个 Ruby 常量,它是 true 和 false 的祖先

    nil . is_a? Boolean2 #=> false Object . new . is_a? Boolean2 #=> false true . to_boolean2 #=> true false . to_boolean2 #=> false nil . to_boolean2 #=> false Object . new . to_boolean2 #=> true Boolean...

    EurekaLog_7.5.0.0_Enterprise

    4)....Fixed: ThreadID = 0 in StandardEurekaNotify 5)....Fixed: Dialog auto-close timer may reset without user input 6)....Fixed: Possible hang when quickly loading/unloading EurekaLog-enabled DLL 7).....

    nil_or:执行除非 Nil

    将此行添加到应用程序的 Gemfile 中: gem 'nil_or' 然后执行: $ bundle 或者自己安装: $ gem install nil_or 用法 我什么时候需要它? 而不是写: date_of_birth = params [ :date_of_birth ] ? params ...

    Anil.zip_matlab例程_matlab_

    Embedding image in image

    Rails的邮件预览引擎MailsViewer.zip

    user_name: nil, password: nil, authentication: nil, enable_starttls_auto: true }, send_if: lambda { |mail| mail.destinations.select { |address| ["yedingding@gmail.com"].include?(address) }.any? ...

    ruby-mailfactory-mime_type

    用ruby发送邮件附件的时候,需要安装mailfactory的插件,但是执行安装命令后会报错:mime-type (>=1.13.1)。该压缩包包含了mailfactory-1.4.0和mime-types-1.15两个文件。

    ios-清理模型中的nil.zip

    清理字典转模型后模型中的nil,属性多于字典,服务器返回为null等情况

    huishouzhan.rar_GetProcAddress_HUISHOUZHA

    然后通过@SHEmptyRecycleBin:=GetProcAddress (LibHandle, SHEmptyRecycleBinA )语句读取SHEmptyRecycleBinA函数的地址,如果以上语句能够正确执行(也就是@SHEmptyRecycleBin不等于nil),那么就调用...

    ds_hash:Ruby 哈希类扩展

    Ruby Hash类扩展。 安装 gem install ds_hash 通过实例学习 哈希。 deep_key? hash = { :a => { :b => 'b' } } hash . deep_key? :a , :b # return true hash . deep_key? :a , :x # return false 哈希。 deep_...

    DENISE.zip_denise_代码反演_全波形反演_全波形反演 时间域_弹性波

    老外的,弹性波时间域全波形反演代码,The DENISE code was ...hn, Denise De Nil and Andr′ e Kurzmann at the Christian- Albrechts-Universit?t Kiel and TU Bergakademie Freiberg (Germany) from 2005 to 2009.

    skyM2.rar_BLUE 完整_BLUE引擎_Blue引擎源码_m2引擎源码_晋升

    不管是飘飘的还是飞尔的都要加解密控件里的一个文件,改名成des.asp,修改unit名为des m2代码里加解密过程里也得加个,nil才能编辑通过 最近发现很多人拿着飘飘 IGE 晋升 飞尔等引擎的源码 四处卖钱 真是无语了,...

    ZXing QRCode Scan

    file_url = nil; wid_ctrl.custom_msg = @"请扫瞄离您最近的iMall二维码,以获取到目的地的路线"; NSMutableSet *readers = [[NSMutableSet alloc] init]; QRCodeReader *qrcode_reader = [[QRCodeReader alloc]...

    Luminati:用于与 Luminati.io-network 通信的 Ruby 包装器

    卢米纳蒂用于与 Luminati.io 网络通信的 ... get_connection ( country : nil , dns_resolution : nil , session : nil )session_id = connection [ :session_id ]proxy_user = connection [ :username ]proxy_passw

    .emacs.d:我的emacs设置。 要使用,请将vn_settings.el放入您的〜.emacs.d文件夹中,并将该行(将“〜.emacs.dvn_settings.el” nil tt加载)添加到您的.emacs中

    .emacs.d:我的emacs设置。 要使用,请将vn_settings.el放入您的〜.emacs.d文件夹中,并将该行(将“〜.emacs.dvn_settings.el” nil tt加载)添加到您的.emacs中

    superobject操作.txt

    superobject使用方法整理。 procedure SaveJson; var json, json_sub: ISuperObject; begin json := SO; json.S['name'] := 'Henri Gourvest'; json.B['vip'] := TRUE; json.O['telephones'] := SA(...

    NiL.JS:.NETJavaScript引擎,用C#编写

    镍 开源ECMAScript 6.0(ES2015)(JavaScript)引擎。 根据BSD 3-条款许可获得许可。... This engine can perform js code on .NET 4 and 4.5, Universal Windows Platform and .NET Core`) " );

    Ruby菜鸟入门指南.md

    4. Ruby中"一切皆表达式"的设计,控制语句、方法定义等都会返回值。 5. Ruby中"一切皆方法调用",没有直接访问属性的方式,只有方法调用。 6. 变量命名约定,如局部变量、常量、实例变量、类变量等。 7. 方法命名...

    active_nothing:Ruby gem,用于在Ruby中模拟Smalltalk的条件

    [ true , false , nil , Object , 0 , 1 , "" , [ 1 , 2 , 3 ] , { } ] . each do | value | value . if_true { p " #{ value } is truthy" } . if_false { p " #{ value } is falsey" } end # Outputs: "true ...

Global site tag (gtag.js) - Google Analytics