Tuesday, August 19, 2008

Programming Ruby 3rd _new topics for me

  • regexp: \p: encoding-aware
  • regexp: &&: [a-z]&&[^aeiou] means match a to z but vowels
  • regexp: named group: /(?<word>\w)\k<word>/ #repeat same words
  • regexp: named group: /(?<hour>\d\d)/;"Hour is #{hour} #it also can refer after as param
  • regexp: sub can get a hash as the replacement param
  • regexp: 'a\b\b'.gsub(/\\/, '\&\&') # => "a\\b\\c"
  • method: pass all params: def initialize(*); super; end
  • method argument with splat: method_one(*[1,2], 3, *(4..8))

No comments: