Last active
April 26, 2019 22:05
-
-
Save nisevi/d2cffea4951a1553fb84530ebad4b176 to your computer and use it in GitHub Desktop.
Algunos métodos de ruby sobre diferentes objetos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = [ "a", "b", "c", "d" ] | |
a.collect {|x| x + "!"} #=> ["a!", "b!", "c!", "d!"] | |
a.map.with_index {|x, i| x * i} #=> ["", "b", "cc", "ddd"] | |
a #=> ["a", "b", "c", "d"] | |
[ "a", nil, "b", nil, "c" ].compact! #=> [ "a", "b", "c" ] | |
[ "a", "b", "c" ].compact! #=> nil | |
[1,2,3,4,5].select {|num| num.even? } #=> [2, 4] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1234.integer? #=> true | |
-12345.abs #=> 12345 | |
36.lcm(60) #=> 180 | |
(-1).next #=> 0 | |
1.succ #=> 2 | |
5.times {|i| print i, " " } #=> 0 1 2 3 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"Ho! " * 3 #=> "Ho! Ho! Ho! " | |
"Ho! " * 0 #=> "" | |
a = "hello " | |
a << "world" #=> "hello world" | |
a << 33 #=> "hello world!" | |
"hello".capitalize #=> "Hello" | |
"HELLO".capitalize #=> "Hello" | |
"123ABC".capitalize #=> "123abc" | |
"hello".center(4) #=> "hello" | |
"hello".center(20) #=> " hello " | |
"hello".center(20, '123') #=> "1231231hello12312312" | |
"hEllO".downcase #=> "hello" | |
"hEllO".upcase #=> "HELLO" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment