Pre determine the size of a string

Hi all,

please, is there a way to pre-determine the size (or capacity) of a
string in ruby?

i.e if a have a string “str” , i will set it to contain characters not
more than 10.

PLEASE DO NOT SHOUT.

2010/6/2 kevid [email protected]:

please, is there a way to pre-determine the size (or capacity) of a
string in ruby?

i.e if a have a string “str” , i will set it to contain characters not
more than 10.

No, strings in Ruby are unbounded. If you need that functionality you
will have to create a class which implements this.

(Note: Ruby != C) :slight_smile:

Kind regards

robert

kevid wrote:

please, is there a way to pre-determine the size (or capacity) of a
string in ruby?

Nope, strings are resized dynamically as required. But you could make
your own class which does this.

It could, for example, delegate to an underlying String object,
intercepting calls which could make the string bigger, and either raise
an error or truncate the error if it exceeds the chosen size.

On 2 June 2010 17:20, Brian C. [email protected] wrote:

But you likely do not need that :wink:
What is your aim ?