Skip to content

Instantly share code, notes, and snippets.

@amuino
Created January 30, 2011 19:22
Show Gist options
  • Save amuino/803146 to your computer and use it in GitHub Desktop.
Save amuino/803146 to your computer and use it in GitHub Desktop.
Example of the weird magic that makes plagelao's kata work without working :-)
# Open irb on the kata directory
ruby-1.9.2-p0 > require "./string_calculator_spec"
=> true
ruby-1.9.2-p0 > s = Separator.new("//[**][+++]\n")
=> /,|
|["**|+++"]/
ruby-1.9.2-p0 > #Ojo al último patrón! Eso matchea cualquier caracter dentro de []
ruby-1.9.2-p0 > "1++2***3".split(s)
=> ["1", "", "2", "", "", "3"]
ruby-1.9.2-p0 > #Separa el primer símbolo, procesa el resto como cadena vacía
ruby-1.9.2-p0 > "10++20***30".split(s)
=> ["10", "", "20", "", "", "30"]
ruby-1.9.2-p0 > #Idem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment