Ian Bicking: the old part of his blog

Ruby python power comment 000

One big difference is overriding or extending built-in type objects. You mentioned the case of an operator, but like you said, that isn't a big deal. But how about overriding existing, or adding new, str methods? You can't tell me that isn't useful!

In Ruby:

class String
  def validate()
    if (self.include?(' '))
      return false
    return true

puts('This should have no spaces'.validate())
>> false

In Python (just a PoC):

def validate():
  if (' ' in self):
    return False
  return True
str.validate = validate

print('This should have no spaces'.validate())
>> TypeError: can't set attributes of built-in/extension type 'str'

Don't get me wrong - I like Python. I use it alot (in fact, these days, more often than Ruby). I just wish it let me setattr on built-in objects.

Comment on Re: Ruby, Python, "Power"
by MonkeeSage