Created
April 14, 2012 14:18
-
-
Save beakr/2384694 to your computer and use it in GitHub Desktop.
Sample DSL.
This file contains hidden or 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 Drinks | |
def initialize(&block) # Initialize drinks | |
@drinks = [] | |
instance_eval &block | |
end | |
def drink(d) | |
@drinks << d | |
end # Add drink | |
def all_drinks | |
puts @drinks | |
end | |
end | |
add_drinks = Drinks.new do | |
drink "water" | |
drink "soda" | |
drink "juice" | |
end | |
add_drinks.all_drinks |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment