Skip to content

Instantly share code, notes, and snippets.

View etiennebarrie's full-sized avatar

Étienne Barrié etiennebarrie

View GitHub Profile
Thread.current[:fiber_local] = :ok
def enumerator
Enumerator.new do |yielder|
yielder.yield Thread.current[:fiber_local]
end
end
p enumerator.next # => nil
# which is explained by, can be reduced to:
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", github: "rails/rails", branch: 'master'
# Defining private methods is less clean using module_function
module ExtendSelf
extend self
def bar
foo
end
private
class Lol
attr_accessor :foo?
end
lol = Lol.new
lol.foo? = 42
p lol.foo?

Keybase proof

I hereby claim:

  • I am etiennebarrie on github.
  • I am etienne (https://keybase.io/etienne) on keybase.
  • I have a public key whose fingerprint is A458 A5E6 9102 E188 AD0E CD57 8401 EA22 480C 61C1

To claim this, I am signing this object:

# 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
require 'test/unit'
class A
def a
end
def method_missing(*)
end
end
class B < A
@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
module LocalMonkeyPatch
def foo
42
end
end
array = []
array.extend LocalMonkeyPatch
p array.foo
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