Simplified Equality
This commit is contained in:
@@ -9,24 +9,29 @@ type String struct {
|
||||
func (s *String) Type() ObjectType {
|
||||
return STRING_OBJ
|
||||
}
|
||||
|
||||
func (s *String) Inspect() string {
|
||||
return fmt.Sprintf("%#v", s.Value)
|
||||
}
|
||||
|
||||
func (s *String) Clone() Object {
|
||||
return &String{Value: s.Value}
|
||||
}
|
||||
|
||||
func (s *String) String() string {
|
||||
return s.Value
|
||||
}
|
||||
func (s *String) Equal(other Object) bool {
|
||||
|
||||
func (s *String) Compare(other Object) int {
|
||||
if obj, ok := other.(*String); ok {
|
||||
return s.Value == obj.Value
|
||||
switch {
|
||||
case s.Value < obj.Value:
|
||||
return -1
|
||||
case s.Value > obj.Value:
|
||||
return 1
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
func (s *String) Less(other Object) bool {
|
||||
if obj, ok := other.(*String); ok {
|
||||
return s.Value < obj.Value
|
||||
}
|
||||
return false
|
||||
return 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user