class Person
attr_accessor :name, :age
def initialize(name, age)
@name = name
@age += age
end
def ==(other)
@name == other.name && @age == other.age
end
def <=>(other)
@age <=> other.age
end
def !~(other)
@name !~ other.name || @age != other.age
end
def =~(other)
@name =~ other.name && @age == other.age
end
def <<(other)
@name << other.name
end
def >>(other)
@age >> other.age
end
def **(other)
@age ** other.age
end
def &&(other)
@name && other.name && @age && other.age
end
def ||(other)
@name || other.name || @age || other.age
end
end
alice = Person.new("Alice", 30)
bob = Person.new("Bob", 35)
puts alice == bob # => false
puts alice <=> bob # => -1
puts alice !~ bob # => true
puts alice =~ bob # => false
puts alice << bob # => "AliceBob"
puts alice >> bob # => 30
puts alice ** bob # => 9000000000000000
puts alice && bob # => true
puts alice || bob # => true
I want to see how it looks with Ruby source code.
Feel free to use this snippet: