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.
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 <alumsimportant@yahoo.ca>:
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
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
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.
--
Posted via http://www.ruby-forum.com/\.
But you likely do not need that
What is your aim ?
On 2 June 2010 17:20, Brian Candler <b.candler@pobox.com> wrote:
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.