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
#Main file | |
require "Twitter.rb" | |
require 'json' | |
require 'uri' | |
Shoes.app :width=>300, :height=>400, :title=>"Rubydubee" do | |
@twitter = Twitter.new "consumer_key", | |
"consumer_secret" | |
@main_stack = stack do |
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=[23,45,576,12] | |
a.each {|x| puts x} |
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
b=a.collect {|x| x**2} | |
puts b |
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.collect! {|x| x**2} |
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','b','c'].each_with_index do |item,index| | |
puts "At Position #{index} : #{item}" | |
end |
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
array = ['junk', 'junk', 'junk', 'val1', 'val2'] | |
3.upto(array.length-1) { |i| puts "Value #{array[i]}" } #This is an example of Integer#upto | |
array = ['1', 'a', '2', 'b', '3', 'c'] | |
0..array.length-1).step(2) do |i| # This is an example of Range#step | |
puts "Letter #{array[i]} is #{array[i+1]}" | |
end |
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
array=[1,2,3,4,5,6] | |
puts array[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
#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] |
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
[4,2,1].sort #[1,2,4] | |
["pradyumna","ruby","bee"].sort #["bee","pradyumna","ruby"] |
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
arrays = [[1,2,3], [100], [10,20]] | |
arrays.sort_by { |x| x.size } # => [[100], [10, 20], [1, 2, 3]] |
OlderNewer