Skip to content

Instantly share code, notes, and snippets.

View chrisroos's full-sized avatar

Chris Roos chrisroos

View GitHub Profile

Reviewing Pull Requests

This was the habit I got into when working on Smart Answers. I'm aware that there have been some changes to the PR process since I last used it so it's possible I'd do things differently next time.

  1. Read the description and comments on the Pull Request

For example, my [PR 269 in the Mocha project][mocha-pr-269].

  1. Create a worktree for the remote branch

GitHub commit ordering

GitHub's ordering of commits is explained in their ["Why are my commits in the wrong order" help page][github-commit-ordering].

  1. Create new repo on GitHub

  2. Clone locally to /tmp/

    $ cd /tmp
  • gstatic.com/generate_204
  • captive.apple.com

gstatic.com

$ curl -v gstatic.com/generate_204
*   Trying 216.58.213.99...

Ruby's class_eval and line number

Using a heredoc

class Foo
  class_eval(<<-EndCode, __FILE__, __LINE__ + 1)
    def my_method
      raise 'bar'
 end
require 'test/unit'
class Parent
class << self
def my_class_method
'class-method'
end
def bound_class_method
method(:my_class_method)
end

Trying to understand how to categorise a rent deposit payment in FreeAgent.


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 unbinding the method I have in ClassMethod.

I end up with the following code in ClassMethod#restore_original_method: