📜 ⬆️ ⬇️

10 reasons to switch to Ruby

I got to know Ruby relatively recently, thanks to the wonderful Ruby on Rails framework . I do not consider myself an expert in Ruby, but I read PickAxe, I wrote several Ruby utilities for personal use, and I also develop on Rails in my free time.

Ruby is currently my primary language. I started with TurboPascal at school, studied C and C ++ at the university, wrote the dissertation in Java , and I also learned PHP from scratch because I wanted to learn how to make websites quickly and easily. I think that writing code for me is a kind of entertainment, and then everything else. In the beginning, I had thoughts about which language to learn, Python or Ruby. I chose the second one because I didn’t want the wrong indents to cause problems with my code.

There are a whole bunch of introductions, guides, articles and essays written by gurus on how to get the most out of Ruby. This article is nothing like this.

This is a more modest, incomplete list of reasons that may (or may not) encourage you to use Ruby, or at least play with it. Caution: if you use another programming language for work or for other purposes - do not complain to me if you no longer want to use it. This is exactly what happened to me, but for me it is not so important. Ruby is a wonderful and elegant language and like so many similar things, it can capture your mind and break your soul.
')
In short, you are warned.

Why learn Ruby?


1.You get all the amenities (pleasure) without tricks.


Ruby borrowed the best from other programming languages, from smalltalk to Java , from Perl to Python . Here are the basic features that you could basically see in other languages:


2. You love the little things.


Ruby is exquisite. Why? Because he does not try to make the code so concise that it would interfere with readability and understanding. There are some tips that can help you:


3. .


? . «Enter» . Ruby Python, , . , C++, . , ?

4. , .


Java, , .
— «, 14 374346.678 — ?»
— «, , !»

Ruby , , . . , :
"YOU SHOULDN'T ALWAYS USE CAPITALS".lowcase # "you shouldn't always use capitals", :
# PHP Code
strtolower("YOU SHOULDN'T ALWAYS USE CAPITALS")

, .

5. .


« return ». , : Ruby , , «return» . .

6. .


, . : , - , . :

Ruby , . .
, ? Numeric, :
class Numeric
def feet
self*3.2808399
end
end

, , , , :
5.feet # 16.4041995
Ruby , . !

7. , , .


, C++, , - — . , , «» «» «». , Ruby . - . , . , Ruby, , , .

8. XML — .


XML — , , , . , , () , — . :
regexp: !ruby/regexp /a-zA-Z/
number: 4.
string: a string

XML, ? YAML, ( ) Ruby, , , .
Ruby XML, YAML , XML, ( Rails). , , :
{"string" => "a string", "number" => 4.7, "regexp" => /a-zA-Z/}.to_yaml
to_yaml, Object, , Ruby. YAML , . , ?

9. — , .


Ruby Lisp Perl Proc. Proc — « , . , .». :
def gen_times(factor)
return Proc.new {|n| n*factor }
end

times3 = gen_times(3)
times5 = gen_times(5)

times3.call(12) #=> 36
times5.call(5) #=> 25
times3.call(times5.call(4)) #=> 60

lambda Proc.new, . , Perl Python ( Lisp). PHP, .
Ruby « Proc», , , each, Array:
[1, 2, 4, 6, 8].each {|c| puts c*2} #=> , 2
, do… end, . Ruby .

10. Rails.


, … Rails -. , PHP, Rails Ruby, , .


. Ruby, , . , , , , — .



— , , (, ) . .

Source: https://habr.com/ru/post/31280/


All Articles