This file contains hidden or 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,b,*c=[1,2,3,4,5] | |
puts c | |
#output : c will become [3,4,5] | |
#3 | |
#4 | |
#5 |
This file contains hidden or 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
array=[12,"pradyumna",23.98] | |
a,b,c=array | |
puts a,b,c |
This file contains hidden or 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,b,c=12,"Pradyumna",23.98 | |
a,b,c=c,a,b | |
puts a,b,c |
This file contains hidden or 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=[1,2,3,4,4,3,3,5] | |
a.delete(3) | |
puts a #[1,2,4,4,5] |
This file contains hidden or 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= [1,2,4,1,5,2,4,1] | |
puts a.uniq # [1,2,4,5] | |
# or just commit it | |
a.uniq! | |
puts a #[1,2,4,5] |
This file contains hidden or 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
class Animal | |
attr_reader :name, :eyes, :appendages | |
def initialize(name, eyes, appendages) | |
@name, @eyes, @appendages = name, eyes, appendages | |
end | |
def inspect | |
@name | |
end |
This file contains hidden or 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
[1, 100,6, 23, 26, 10000].sort do |x, y| | |
x == 6 ? 1 : x <=> y | |
end | |
# => [1, 23, 26, 100, 10000, 6] |
This file contains hidden or 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
arrays = [[1,2,3], [100], [10,20]] | |
arrays.sort_by { |x| x.size } # => [[100], [10, 20], [1, 2, 3]] |
This file contains hidden or 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
[4,2,1].sort #[1,2,4] | |
["pradyumna","ruby","bee"].sort #["bee","pradyumna","ruby"] |
This file contains hidden or 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
#Union | |
[1,2,3] | [1,4,5] # => [1, 2, 3, 4, 5] | |
#Intersection | |
[1,2,3] & [1,4,5] # => [1] | |
#Difference | |
[1,2,3] - [1,4,5] # => [2, 3] |