NilClass
puts "OK" if contact
OK
=> nil
puts "OK" unless c...">
contact.class
=> NilClass
puts "OK" if contact
OK
=> nil
puts "OK" unless contact
=> nil
contact == nil
=> true
puts "OK" if contact
OK
=> nil
puts "OK" if nil
=> nil
class ProxyClass
silence_warnings { instance_methods.each { |m| undef_method m unless m =~ /^__/ } }
def initialize(target)
@target = target
end
private
def method_missing(called, *args, &block)
@target.__send__(called, *args, &block)
end
end
:
>> @nil_object1 = nil
=> nil
>> @nil_object2 = ProxyClass.new(@nil_object1)
=> nil
>> @nil_object1.object_id
=> 4
>> @nil_object2.object_id
=> 4
>> @nil_object2.__id__
=> 2198992980
>> @nil_object1.__id__
=> 4
Source: https://habr.com/ru/post/97802/
All Articles