# ActiveSupport::MultyByte car and cdr? Or 'head' and 'rest'

**URL:** <https://www.ruby-forum.com/t/activesupport-multybyte-car-and-cdr-or-head-and-rest/128573>\
**Category:** Rails\
**Created:** [February 8, 2008, 11:31pm UTC](https://www.ruby-forum.com/t/activesupport-multybyte-car-and-cdr-or-head-and-rest/128573 "2008-02-08T23:31:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steven\_GSHarms](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/2bfe46/32.png) [@Steven\_GSHarms](https://www.ruby-forum.com/u/Steven_GSHarms)\
**Post date:** [February 8, 2008, 11:31pm UTC](https://www.ruby-forum.com/t/activesupport-multybyte-car-and-cdr-or-head-and-rest/128573/1 "2008-02-08T23:31:40Z")

</div>

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
