Ruby-Syntax
Symbols and Strings
:Symbol
"String"
name = "Roger"
"My Name is #{name}"
"String"
name = "Roger"
"My Name is #{name}"
Instance variable
@instance_variable
Arrays
my_array = ['one ' , 'two', 'three']
my_array[0]
my_array.first
my_array[0]
my_array.first
Hash table
my_hash = {:fish => "Salmon"}
my_hash[:fish]
my_hash[:fish]
Block
my_array.each do |an_element|
puts an_element
end
puts an_element
end
my_array.each_with_index do |an_element, index|
puts "#{an_element} is number #{index}"
end
puts "#{an_element} is number #{index}"
end
Class
class RedCar < Car
end
end
Ruby specific tags in HTML templates
<%# Comment -%>
<%= link_to "Google", "http://google.com" -%>
<%= my_array.each_with_index do |an_element, index| -%>
<%= puts an_element -%>
<%= end -%>
<%= link_to "Google", "http://google.com" -%>
<%= my_array.each_with_index do |an_element, index| -%>
<%= puts an_element -%>
<%= end -%>
Siehe auch