Skip to content

Instantly share code, notes, and snippets.

@ybenjo
Created October 4, 2010 03:26
Show Gist options
  • Save ybenjo/609213 to your computer and use it in GitHub Desktop.
Save ybenjo/609213 to your computer and use it in GitHub Desktop.
class Object
def to_i_or_nil
if self.nil?
return nil
else
return self.to_i
end
end
end
if $0 == __FILE__
p 10.to_i_or_nil
p 0.to_i_or_nil
p nil.to_i_or_nil
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment