Profile Picture

Hi, I'm Bobby Matson.

I'm a NYC-based software engineer and entrepreneur. I love working on new business models and experimenting with funky ideas. Shoot me an email if you'd like to collaborate on one!

Bobby's Blog

Metaprogramming

code that thinks of program structure as just another thing to manipulate

Object#send

Treats object as giant case statement (sending a message to an object)

Really a way to pass args to another method (send) where the actual code it triggered

  class Foo
    def bar(*args)
    end
  end

  foo = Foo.new
  foo.send(:bar, 'args', 1)

Look into cont_get

#method_missing

Project#name_changed?
Project#milestone_changed?

This is called after Ruby has tried looking up the method call on the class & superclasses

Need a fallback to super. The lookup chain will stop at that class and error (if its a subclass, this would be bad!)

Need to define a respond_to_missing?

Need to define the method within the method_missing call

Method missing is good for dynamic DSLs, delegators

#define_method

['url', 'name'].each do |method|
  define_method "photo_#{method}" do
    photo.send(method)
  end
end

#include

Defines an anonymous module at the end of the class definition. include instance_methods

#hooks

  • .inherited
  • .included
  • .extended

Her advice: don’t use these!