3 ms·
In ruby, #2 is as simple as num = 42 def num.to_whatever "whatever" end num.to_whatever # => 42 41.to_whatever # => NoMethodError
by steveklabnik 16y ago
In ruby, #2 is as simple as
num = 42
def num.to_whatever
"whatever"
end
num.to_whatever # => 42
41.to_whatever # => NoMethodError
I agree with my sibling, though. It might be better that this is harder in Python. It's a bad idea, generally.