Skip to content

Instantly share code, notes, and snippets.

View bbuckley's full-sized avatar

Brian K. Buckley bbuckley

View GitHub Profile
#! ruby19
require 'date'
class EndlessEnum
include Enumerable
def initialize(x, method = :succ)
@x = x
@method = method
@bbuckley
bbuckley / album.rb
Created October 25, 2009 14:42 — forked from rklemme/album.rb
require 'yaml'
Track = Struct.new :title, :duration
# An Album represents an audio medium which has title,
# interpret, a pause duration between tracks and a list
# of individual tracks.
class Album
attr_reader :title, :interpret, :pause
# By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6^(th) prime is 13.
#
# What is the 10001^(st) prime number?
require 'mathn'
puts Prime.instance.each.tap{ |x| 10000.times{ x.next} }.next #104743
include Enumerable
def each
return Enumerator.new(self,:each) unless block_given?
yield 1
yield 2
end
puts each.inject(:+).inspect
puts each{|x| x * x}.inject(:+).inspect
[12,3,4,5].map{|x| x * 2}.inspect
:foo / :bar # => [:foo, :bar]
:foo / :bar / :fizz # => [:foo, :bar, :fizz]
:foo / :bar / :foo # => [:foo, :bar]
:foo / :bar / :fizz / :bizz # => [:foo, :bar, :fizz, :bizz]