Skip to content

Instantly share code, notes, and snippets.

@rubydubee
rubydubee / array_range.rb
Created June 30, 2011 21:58
Array Range Example
array=[1,2,3,4,5,6]
puts array[2..4]
@rubydubee
rubydubee / array_example4.rb
Created June 30, 2011 21:48
Array Example 4
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
@rubydubee
rubydubee / array_indexes.rb
Created June 30, 2011 21:44
Array Indexes
['a','b','c'].each_with_index do |item,index|
puts "At Position #{index} : #{item}"
end
@rubydubee
rubydubee / array_example3.rb
Created June 30, 2011 21:43
Array Example 3
a.collect! {|x| x**2}
@rubydubee
rubydubee / array_example2.rb
Created June 30, 2011 21:41
Array Example 2
b=a.collect {|x| x**2}
puts b
@rubydubee
rubydubee / array_example1.rb
Created June 30, 2011 21:39
Array Example 1
a=[23,45,576,12]
a.each {|x| puts x}
@rubydubee
rubydubee / main.rb
Created June 30, 2011 19:48
Twitter Client in shoes
#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