Looking to write a Tag class

Posted by Austin Schneider on Stack Overflow See other posts from Stack Overflow or by Austin Schneider
Published on 2010-04-13T03:22:07Z Indexed on 2010/04/13 3:22 UTC
Read the original article Hit count: 406

Filed under:
|
|

I'm looking to write a Tag class (a tag is a string with no spaces). My first thought is to inherit from String:

class Tag < String
  def initialize(str)
    raise ArgumentError if str =~ /\s/
    super
  end
end

Does this look correct? Are there any other methods I should redefine?

© Stack Overflow or respective owner

Related posts about ruby

Related posts about tag