Skip to content

Instantly share code, notes, and snippets.

View etiennebarrie's full-sized avatar

Étienne Barrié etiennebarrie

View GitHub Profile
o = Object.new
def o.==(num)
true
end
puts o == 42
puts [o].include?(42)
puts [o].include?("a")
puts [o].include?(nil)
puts [o].include?(Object.new)
require 'rubygems'
require 'rspec'
class Sequence
def initialize(*elements)
@elements = elements.sort
end
def elements
@elements.dup
class Foo
CONST = 42
end
class Bar < Foo
def self.foo
CONST
end
class << self
class InfoDesk
def trains
:trains
end
def flights
:flights
end
def buses
:buses
end
[branch]
# git checkout foo automatically checks out origin/foo and names it foo and sets tracking branch.
autosetupmerge = true
# automatically set tracking branch to rebase instead of merge
autosetuprebase = always
[diff]
# automatically detects renames
renames = true
[rebase]
# automatically sets --autosquash when rebasing interactively
Wrong = Class.new(Exception)
Right = Class.new(StandardError)
begin
raise Wrong, "Can't be rescued easily"
rescue
puts "Not reached"
rescue Wrong
puts "#{$!}, have to be explicitely rescued"
end
module LocalMonkeyPatch
def foo
42
end
end
array = []
array.extend LocalMonkeyPatch
p array.foo
@etiennebarrie
etiennebarrie / foo.rb
Created March 2, 2012 10:03
c’est fou fou
class Foo
def foo(*args)
puts(*args)
end
def bar
foo = 42
foo foo
end
end
require 'test/unit'
class A
def a
end
def method_missing(*)
end
end
class B < A
# Using Array#assoc instead of a Hash when comparing using only ==
require 'test/unit/assertions'
include Test::Unit::Assertions
class Foo
def initialize(i)
@i = i
end