Skip to content

Instantly share code, notes, and snippets.

@burtlo
Created May 6, 2012 03:15
Show Gist options
  • Save burtlo/2607598 to your computer and use it in GitHub Desktop.
Save burtlo/2607598 to your computer and use it in GitHub Desktop.
Ruby DSL, the hard way
require 'rspec'
class Recipe
attr_accessor :name
def initialize(name)
@name = name
end
end
expected_recipe = Recipe.new "Chocolate Chip Cookies"
def Create(p)
# puts [__method__, p]
class_name, method_name, parameter = p
class_name.send(method_name,parameter)
end
def new(p)
# puts [__method__, p]
p.insert(1,__method__)
end
def recipe(p)
# puts [__method__, p]
[ Recipe, p.last ]
end
def named(p) ; [__method__, p] ; end
recipe = Create new recipe named "Chocolate Chip Cookies"
recipe.should == expected_recipe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment