PRE DETERMINE THE SIZE OF A STRING

K

kevid

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.
 
R

Robert Klemme

PLEASE DO NOT SHOUT.

2010/6/2 kevid said:
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) :)

Kind regards

robert
 
B

Brian Candler

kevid said:
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.
 
B

Benoit Daloze

[Note: parts of this message were removed to make it a legal post.]

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.
But you likely do not need that ;)
What is your aim ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,154
Messages
2,570,870
Members
47,400
Latest member
FloridaFvt

Latest Threads

Top