Skip to content

Instantly share code, notes, and snippets.

View denisdefreyne's full-sized avatar

Denis Defreyne denisdefreyne

View GitHub Profile
"snow" + "plow" == "snowplow"
# => true
("snow" + "plow").equal?("snowplow")
# => false
"/usr/bin/ruby" == path # => true
"/usr/bin/python" == path # => false
path = Path.new("usr", "bin", "ruby")
path == path # => true
path == "/usr/bin/ruby" # => true
path == "/usr/bin/python" # => false
path == 12.3 # => false
class Path
# …
def ==(other)
other.respond_to?(:to_str) &&
to_str == other.to_str
end
def to_str
string
end
path = Path.new("usr", "bin", "ruby")
path.string == "/usr/bin/ruby" # => true
path == "/usr/bin/ruby" # => false :(
class Path
# …
def ==(other)
self.class == other.class &&
@components == other.components
end
end
path = Path.new("usr", "bin", "ruby")
path.string # => "/usr/bin/ruby"
class Path
attr_reader :components
def initialize(*components)
@components = components
end
def string
"/" + @components.join("/")
end
float_two = 2.0
integer_two = 2
denis = Employee.new(570, "Denis Defreyne")
also_denis = Employee.new(570, "Denis")
denis_v = Employee.new(992, "Denis Villeneuve")
new_denis_1 = Employee.new(nil, "Denis 1")
new_denis_2 = Employee.new(nil, "Denis 2")
denis == denis # => true
denis == also_denis # => true
denis == "cucumber" # => false
denis == denis_v # => false