Wiki source for RubySyntax


Show raw source

=====Ruby-Syntax=====

Symbols and Strings
%%(ruby)
:Symbol
"String"
name = "Roger"
"My Name is #{name}"
%%

Instance variable
%%(ruby)
@instance_variable
%%

Arrays
%%(ruby)
my_array = ['one ' , 'two', 'three']
my_array[0]
my_array.first
%%

Hash table
%%(ruby)
my_hash = {:fish => "Salmon"}
my_hash[:fish]
%%

Block
%%(ruby)
my_array.each do |an_element|
puts an_element
end
%%

%%(ruby)
my_array.each_with_index do |an_element, index|
puts "#{an_element} is number #{index}"
end
%%

Class
%%(ruby)
class RedCar < Car

end
%%


Ruby specific tags in HTML templates
%%(ruby)
<%# Comment -%>
<%= link_to "Google", "http://google.com" -%>

<%= my_array.each_with_index do |an_element, index| -%>
<%= puts an_element -%>
<%= end -%>

%%


----
Siehe auch {{backlinks}}
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki