rors.org

Personal website of Dejan Simic, a Ruby On Rails developer working for Less Everything

Alternative join and split in Ruby

Join

>> %w(tic tac toe) * "-" 
=> "tic-tac-toe"

Split

>> "tic-tac-toe" / "-" 
=> ["tic", "tac", "toe"]

Unfortunately, for split you’ll need this of course:

class String
  alias / :split
end

;)

  • Karl on 2008-07-10

    Just my opinion here, but I don’t like either of those conventions. To me they are not clear. If someone else was picking up my code, they might find those a bit confusing. The split nomenclature is farily common among several languages.

    But I will give you that they are concise.

Any thoughts?



Fork me on GitHub