Programming Ruby 1.9 (3rd edition): The Pragmatic Programmers' Guide / Программирование на Ruby 1.9 (3-е издание): Руководство прагматичного программиста

→verbose_greet("Dave", "loyal customer") { puts "Hi" }
0 &nbsp;&nbsp;&nbsp;&nbsp;<code>verbose_greet("Dave", "loyal customer") { puts "Hi" }</code>
→greet { puts "Hi" }
0 &nbsp;&nbsp;&nbsp;&nbsp;<code>greet { puts "Hi" }</code>
→So is this:
0 А также:
→do
0 <code>&nbsp;&nbsp;&nbsp;&nbsp;do
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;club.enroll(person)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;person.socialize
&nbsp;&nbsp;&nbsp;&nbsp;end</code>
→{ puts "Hello" }
0 <code>&nbsp;&nbsp;&nbsp;&nbsp;{ puts "Hello" }</code>
→Blocks and Iterators
0 <b>Блоки и итераторы</b>
→line.gsub(/Perl|Python/, 'Ruby')
0 &nbsp;&nbsp;&nbsp;&nbsp;<code>line.gsub(/Perl|Python/, 'Ruby')</code>
→line.sub(/Perl/, 'Ruby') # replace first 'Perl' with 'Ruby'
0 <code>&nbsp;&nbsp;&nbsp;&nbsp;line.sub(/Perl/, 'Ruby') # replace first 'Perl' with 'Ruby'
&nbsp;&nbsp;&nbsp;&nbsp;line.gsub(/Python/, 'Ruby') # replace every 'Python' with 'Ruby'</code>
→if line =~ /Perl|Python/
0 <code>&nbsp;&nbsp;&nbsp;&nbsp;if line =~ /Perl|Python/
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "Scripting language mentioned: #{line}"
&nbsp;&nbsp;&nbsp;&nbsp;end</code>
→/\d\d:\d\d:\d\d/ # a time such as 12:34:56
0 <code>&nbsp;&nbsp;&nbsp;&nbsp;/\d\d:\d\d:\d\d/ # a time such as 12:34:56
&nbsp;&nbsp;&nbsp;&nbsp;/Perl.*Python/ # Perl, zero or more other chars, then Python
&nbsp;&nbsp;&nbsp;&nbsp;/Perl Python/ # Perl, a space, and Python
&nbsp;&nbsp;&nbsp;&nbsp;/Perl *Python/ # Perl, zero or more spaces, and Python
&nbsp;&nbsp;&nbsp;&nbsp;/Perl +Python/ # Perl, one or more spaces, and Python
&nbsp;&nbsp;&nbsp;&nbsp;/Perl\s+Python/ # Perl, whitespace characters, then Python
&nbsp;&nbsp;&nbsp;&nbsp;/Ruby (Perl|Python)/ # Ruby, a space, and either Perl or Python</code>
→inst_section = {
0 <code>&nbsp;&nbsp;&nbsp;&nbsp;inst_section = {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'cello' => 'string',
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'clarinet' => 'woodwind',
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'drum' => 'percussion',
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'oboe' => 'woodwind',
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'trumpet' => 'brass',
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'trumpet' => 'brass',
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'violin' => 'string'
&nbsp;&nbsp;&nbsp;&nbsp;}</code>
→Variables Constants and Local Global Instance Class Class Names
0 <table border="0" cellpadding="0" cellspacing="0" width="600px">
<tbody><tr><td colspan="4" width="80%">Variables </td><td rowspan="2" width="20%">Constants and Class Names</td></tr><tr><td>Local </td><td>Global </td><td>Instance </td><td>Class </td></tr><tr><td>name </td><td>$debug</td><td>@name</td><td>@@total</td><td>PI</td></tr><tr><td>fish_and_chips</td><td>$CUSTOMER</td><td>@point_1</td><td>@@symtab</td><td>FeetPerMile</td></tr><tr><td>x_axis</td><td>$_</td><td>@X</td><td>@@N</td><td>String</td></tr><tr><td>thx1138</td><td>$plan9</td><td>@_</td><td>@@x_pos</td><td>MyClass</td></tr><tr><td>_26</td><td>$Global</td><td>@plan9</td><td>@@SINGLE</td><td>JazzSong</td></tr></tbody></table>
→Arrays and Hashes
0 <b>Массивы и хеши</b>
→a = [ 'ant', 'bee', 'cat', 'dog', 'elk' ]
a[0] # => "ant"
a[3] # => "dog"
# this is the same:
a = %w{ ant bee cat dog elk }
a[0] # => "ant"
a[3] # => "dog"
0 <code>&nbsp;&nbsp;&nbsp;&nbsp;a = [ 'ant', 'bee', 'cat', 'dog', 'elk' ]
&nbsp;&nbsp;&nbsp;&nbsp;a[0] # =&gt; "ant"
&nbsp;&nbsp;&nbsp;&nbsp;a[3] # =&gt; "dog"
&nbsp;&nbsp;&nbsp;&nbsp;# this is the same:
&nbsp;&nbsp;&nbsp;&nbsp;a = %w{ ant bee cat dog elk }
&nbsp;&nbsp;&nbsp;&nbsp;a[0] # =&gt; "ant"
&nbsp;&nbsp;&nbsp;&nbsp;a[3] # =&gt; "dog"</code>
→a = [ 1, 'cat', 3.14 ] # array with three elements
0 <code>&nbsp;&nbsp;&nbsp;&nbsp;a = [ 1, 'cat', 3.14 ] # array with three elements
&nbsp;&nbsp;&nbsp;&nbsp;puts "The first element is #{a[0]}"
&nbsp;&nbsp;&nbsp;&nbsp;# set the third element
&nbsp;&nbsp;&nbsp;&nbsp;a[2] = nil
&nbsp;&nbsp;&nbsp;&nbsp;puts "The array is now #{a.inspect}"</code>
→Good night, Ma
0 &nbsp;&nbsp;&nbsp;&nbsp;<code>Good night, Ma</code>
→def say_goodnight(name)
0 &nbsp;&nbsp;&nbsp;&nbsp;<code>def say_goodnight(name)</code>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<code>"Good night, #{name.capitalize}"</code>
&nbsp;&nbsp;&nbsp;&nbsp;<code>end</code>
&nbsp;&nbsp;&nbsp;&nbsp;<code>puts say_goodnight('ma')</code>
→Good night, Uncle
0 &nbsp;&nbsp;&nbsp;&nbsp;<code>Good night, Uncle</code>
→def say_goodnight(name)
0 &nbsp;&nbsp;&nbsp;&nbsp;<code>def say_goodnight(name)</code>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<code>result = "Good night, #{name.capitalize}"</code>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<code>return result</code>
&nbsp;&nbsp;&nbsp;&nbsp;<code>end</code>
&nbsp;&nbsp;&nbsp;&nbsp;<code>puts say_goodnight('uncle')</code>
→Good night, Pa
0 &nbsp;&nbsp;&nbsp;&nbsp;<code>Good night, Pa</code>
Резюме
Пол:
мужчина
Родной язык:
русский
С нами:
с 19 сентября 2010 г. (5874 дня) по приглашению izolenta
Деятельность:
426 версий перевода с общим рейтингом 9
27 комментариев
Карма: 5 (оценок: 5)
Написать white_rabbit личное сообщение