Delegate id raise RuntimeError exception when allow_nil is true #3545

ka8725 opened this Issue Nov 7, 2011 · 1 comment


None yet
2 participants

ka8725 commented Nov 7, 2011

Here is explanation how to reproduce problem
`>> class A

delegate :id, :to => :b, :allow_nil => true
attr_accessor :b
=> nil
RuntimeError: Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
from (irb):12:in __send__' from (irb):12:inid'
from (irb):14
The problem is in NilClass that defines id method and raises RuntimeException.


tenderlove commented Nov 7, 2011

Making this change seems very bad. Changing the behavior of nil would impact your entire system. I suggest:

  1. Not allowing nil
  2. Changing your method name to something besides id
  3. Write your own method that delegates and does a nil check

tenderlove closed this Nov 7, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment