Steven G. Harms
2008-Feb-08 22:29 UTC
ActiveSupport::MultyByte car and cdr? Or ''head'' and ''rest''
Hi, I''m working on an application which involves looking at words that have macrons ( that''s the "long sound" bar over a letter ). Under certain spellings the macrons move from macron-ized to ''no macron''. I tried to do this in Ruby without any help, but ultimately friends and saner voices convinced me that given Ruby''s current state with respect to UTF-8 i would be saved many sleepless nights by including ActiveSupport::Multibyte. And boy did it help! Yay! Nevertheless, as I''ve written modules to deal with the aString.chars[x..y] to retrieve characters ( versus simple bytes ( which may or may not completely map to a character! )), I''ve found myself writing simple recursive functions whose work would have been made more simple by: macronizedString.firstChar ( or the ''car'' if you Lisp ) macronizedString.restOfString ( or the ''cdr'' if you Lisp ). or macronizedString.lastChar Is there a reason these are not included? I don''t mean "hey get off your butts and write these for me" , I mean it more in the sense of "am I so dumb that I''m not using the true power of the module to do things the easy way - versus writing painful functions". For example ''lastChar'' works along the lines of firstChar = macronizedString.chars[0] lastChar = macronizedString.chars[0..macronizedString.jlength-1] restOfString = macronizedString.chars[1..99] # assuming string < 99 chars, probably not safe, surely there''s a better way? Thanks to Ruby''s slick "extend class" I was thinking about adding these methods in....am I doing a good thing or a foolish thing? Am I doing it in a sapient or foolish manner? Thanks, Steven --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---