This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo | |
def bar | |
puts "baz" | |
end | |
end | |
proxied = Foo.new | |
proxy = Object.new | |
proxy.instance_eval do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rspec' | |
require 'savon' | |
require 'savon_spec' | |
RSpec.configure do |config| | |
config.include Savon::Spec::Macros | |
end | |
describe do | |
before(:each) do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A | |
def a | |
puts 'foo' | |
end | |
def b | |
a | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |