Advertisement
saasbook

fib.rb

Jan 10th, 2012
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.30 KB | None | 0 0
  1. # Fibonacci iterator should be callable like this:
  2. f = FibSequence.new(6) # just the first 6 Fibonacci numbers
  3. f.each { |s| print(s,':') }  # => 1:1:2:3:5:8:
  4. f.reject { |s| s.odd? }      # => [2, 8]
  5. f.reject(&:odd?)             # => [2, 8] (a shortcut!)
  6. f.map { |x| 2*x }            # => [2, 2, 4, 6, 10, 16]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement