Skip to content

Instantly share code, notes, and snippets.

View timabdulla's full-sized avatar

Tim Abdulla timabdulla

View GitHub Profile
@timabdulla
timabdulla / gist:2dda8cb8dfea980a96a6
Last active August 29, 2015 14:10
strangeness with double splats
def meth_with_no_args
end
args = []
# the splat expands the args array, but because the array is empty, the expansion results in no args being sent to the method, thus satisfying the method's requirement that it receive no args when being invoked.
meth_with_no_args(*args)
kw_args = {}
# the double-splat expands the keyword-arguments hash, and even though the hash is empty and should result in no args being sent to the method, an ArgumentError is raised by the invocation of the method for sending 1 argument to it when there should be none.
meth_with_no_args(**kw_args)
@timabdulla
timabdulla / gist:5977231
Created July 11, 2013 17:00
demonstrating the behaviour of Mutex#sleep
require 'thread'
mutex = Mutex.new
t1 = Thread.new do
mutex.synchronize do
mutex.sleep
# we've now been woken up, and we'll try and reacquire the mutex
puts "woken up - mutex locked: #{mutex.locked?}"
end
@timabdulla
timabdulla / gist:3559697
Created August 31, 2012 21:55
stack level too deep (SystemStackError)
class Foo
def bar
puts "baz"
end
end
proxied = Foo.new
proxy = Object.new
proxy.instance_eval do
@timabdulla
timabdulla / savon_spec_inconsistency.rb
Created August 9, 2012 17:07
savon_spec inconsistency
require 'rspec'
require 'savon'
require 'savon_spec'
RSpec.configure do |config|
config.include Savon::Spec::Macros
end
describe do
before(:each) do
def notify_done(f)
f_prime = ->(*args) do
puts 'done!'
f.call(*args)
end
f.receiver.class.send(:define_method, f.name, &f_prime)
end
def foo
class A
def a
puts 'foo'
end
def b
a
end
end
@timabdulla
timabdulla / gist:3018908
Created June 29, 2012 16:16
Strangeness with eigenclasses
class A; end
class B < A; end
def eigen(c); class << c; self; end; end;
eigen(B).ancestors # => [Class, Module, Object, Kernel, BasicObject]
eigen(B).superclass # => #<Class:A>