Class: Mingle::MingleString

Inherits:
MingleValue
  • Object
show all
Extended by:
Forwardable
Includes:
Comparable
Defined in:
lib/mingle.rb

Overview

Note: it’s important that this class be defined before things like MingleNamespace, MingleIdentifier, etc, which register parse handlers for values of type MingleString.

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ MingleString

Returns a new instance of MingleString.



38
39
40
# File 'lib/mingle.rb', line 38

def initialize( str )
    @str = not_nil( str, "str" ).to_s.dup
end

Instance Method Details

#<=>(other) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/mingle.rb', line 43

def <=>( other )
    
    if other.class == self.class
        @str <=> other.str
    else
        raise TypeError, "Not a #{self.class}: #{other.class}"
    end
end

#==(other) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/mingle.rb', line 63

def ==( other )
    
    return true if other.equal?( self )
    return false unless other.is_a?( MingleString )

    other_str = other.instance_variable_get( :@str )
    @str == other_str
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/mingle.rb', line 73

def eql?( other )
    self == other
end

#hashObject



78
79
80
# File 'lib/mingle.rb', line 78

def hash
    @str.hash
end

#inspectObject



58
59
60
# File 'lib/mingle.rb', line 58

def inspect
    to_s.inspect
end

#to_iObject



83
84
85
# File 'lib/mingle.rb', line 83

def to_i
    @str.to_i
end

#to_sObject



53
54
55
# File 'lib/mingle.rb', line 53

def to_s
    @str.to_s
end