From: kevid on 2 Jun 2010 11:07 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.
From: Robert Klemme on 2 Jun 2010 11:19 PLEASE DO NOT SHOUT. 2010/6/2 kevid <alumsimportant(a)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/
From: Brian Candler on 2 Jun 2010 11:20 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/.
From: Benoit Daloze on 2 Jun 2010 16:50 [Note: parts of this message were removed to make it a legal post.] On 2 June 2010 17:20, Brian Candler <b.candler(a)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. > > But you likely do not need that ;) What is your aim ?
|
Pages: 1 Prev: mod_ruby and 1.9 Next: Simple hack to get $500 to your home. |