Monday, August 18, 2008

Programming Ruby 3rd

New topics -p118
  • Hash new idiom: { cell: 'string', clarinet: 'woodwind'}
  • require_relative
  • be capable Comparable: def <=>(other)
  • be capable Enumerable: def each
  • unit test
  • parameters to a block are always local to a block
  • [1,2,3].each {|value; square| square} #square is local
  • inject(:+)
  • external iterator: [1,2,3].to_enum.next
  • enumerator makes objects enumerable
  • enumerator stops loop
  • -> { puts 'hello'}, -> arg, *ary, &block { |e| ... }
  • 3 + 4.im
  • string encoding
  • Song = Struct.new(:title, :name, :length); Song.new('hello', 'John', 3.14)

No comments: