GitHub's ordering of commits is explained in their ["Why are my commits in the wrong order" help page][github-commit-ordering].
-
Create new repo on GitHub
-
Clone locally to /tmp/
$ cd /tmp
require 'test/unit' | |
class Parent | |
class << self | |
def my_class_method | |
'class-method' | |
end | |
def bound_class_method | |
method(:my_class_method) | |
end |
Demo of interacting with stockfish.js engine - https://chrisroos.github.io/upgraded-waddle/?#.
ruby -run -e httpd . -p 9090
From http://stackoverflow.com/questions/3108395/serve-current-directory-from-command-line.
Trying to understand how to categorise a rent deposit payment in FreeAgent.
This follows on from https://gist.github.com/chrisroos/fc62b8e0ce30288abba6a3762b2cb1ee.
# The output below is from using Ruby 1.8.7
# The "singleton method bound for a different object" errors don't occur in Ruby 1.9.3 or above
class Foo
def self.my_class_method
"#{self}.class-method"
end
I'm trying to synchronise the implementations of ClassMethod#restore_original_method
and AnyInstanceMethod#restore_original_method
in the hope that I can then remove the duplication.
In ClassMethod
the @original_method
is a Method
(i.e. it's bound). In AnyInstanceMethod
the @original_method
is an UnboundMethod
. I presume it's not possible to get hold of a bound method in AnyInstanceMethod
as the class hasn't been instantiated at the point we get hold of it.
The define_method
method accepts either a Method
or UnboundMethod
as the second argument. Although I can't use this form in Ruby 1.8.7 because of the "singleton method bound for a different object" problem (see https://gist.github.com/chrisroos/fc62b8e0ce30288abba6a3762b2cb1ee).
Given that I don't think I can get a bound Method
in AnyInstanceMethod
that means unbind
ing the method I have in ClassMethod
.
I end up with the following code in ClassMethod#restore_original_method
:
I've been investigating why the behaviour of ClassMethod#restore_original_method
is different between Ruby 1.8.x and all others versions. See [line 77 of ClassMethod][class-method-line-77].
It turns out that there appears to be a problem in 1.8.7 with using define_method
when the method
argument is a singleton method. This can be illustrated with the following code:
class Foo
class << self
def my_class_method
'Foo.my_class_method'
end