One of the struggles with learning Ruby is that, like smalltalk et al, you get to pass code around as well as data.
One way you can pass code to a method is with a code block.
You can then call the code block in the method definition with yield which says "insert this block of code in place of yield":
def do_it
yield
end
do_it { 2 + 4 }
=> 6
You also get to send parameters into the code block from the method definition.
That's where the |t| comes in:
def do_it_with_ten
yield 10
end
do_it_with_ten { |t| (2 + 4) * t }
=> 60
Note that the curly braces are equivalent to do..end.
I'm guessing that this is the code you found with yield in it:
def create_table(name, options = {})
table_definition = TableDefinition.new(self)
table_definition.primary_key(options[:primary_key] || "id") unless options[:id] == false
yield table_definition
if options[:force]
drop_table(name) rescue nil
end
create_sql = "CREATE#{' TEMPORARY' if options[:temporary]} TABLE "
create_sql << "#{name} ("
create_sql << table_definition.to_sql
create_sql << ") #{options[:options]}"
execute create_sql
end
This is exactly what you're looking for. This is the definition of the create_table method we are calling. You can see the yield with the parameter table_definition.