Confusion with Strings

From the book I read a line about string :

"If you try to set part of the string that doesn’t exist— ***a too-high
or
too-low numerical index***, or a string or regular expression that
doesn’t match the string—you get a fatal error."

Could you give one example against the line within ****?

Thanks in advance.

···

--
Posted via http://www.ruby-forum.com/.

Are you really saying that you don't understand the concept of one
number being higher than another?! Try it for yourself in IRB!
And all this after saying "The whole topic is understood by me." about
blocks and parenthetical parsing!

···

--
Posted via http://www.ruby-forum.com/.

From the book I read a line about string :

"If you try to set part of the string that doesn’t exist— ***a too-high
or
too-low numerical index***, or a string or regular expression that
doesn’t match the string—you get a fatal error."

Could you give one example against the line within ****?

Thanks in advance.

--
Posted via http://www.ruby-forum.com/\.

Do you know how to set any part of a string using a numerical index?

For example, if I wrote the following in irb:

s = "hello"

=> "hello"

could you set the "e" to "u", so that

s == "hullo" # => true

?

Once you can do that, try it with different numerical indices.

···

On 12 March 2013 19:25, Love U Ruby <lists@ruby-forum.com> wrote:

@Scott.

yes I do here it ia:

s = "hello"

=> "hello"

s["e"] = "u"

=> "u"

s

=> "hullo"

The answer to the line **a too-high or too-low numerical index **

str = 'aaa'

=> "aaa"

str[-4] = "x"

IndexError: index -4 out of string
        from (irb):57:in `='
        from (irb):57
        from C:/Ruby193/bin/irb:12:in `<main>'

str[-5] = "x"

IndexError: index -5 out of string
        from (irb):58:in `='
        from (irb):58
        from C:/Ruby193/bin/irb:12:in `<main>'

str[4] = "x"

IndexError: index 4 out of string
        from (irb):59:in `='
        from (irb):59
        from C:/Ruby193/bin/irb:12:in `<main>'

Actually that word `too big` and `too small` made me to think too much..
lollzzzzzzz.

Guys if my understanding with the line is wrong then please correct me.

···

--
Posted via http://www.ruby-forum.com/\.

For some reason the page won't load for me :confused: I'll just assume it's the
one about someone being wrong on the internet.

···

--
Posted via http://www.ruby-forum.com/.

Hi,

I have some confusion with "ancestor" method.

Can you help me out to clear the concept?

class A
end

A.ancestors # => [A, Object, Kernel, BasicObject] <~~ Here why came? I
actually expect the output as below one.

A.class.ancestors # => [Class, Module, Object, Kernel, BasicObject]

···

--
Posted via http://www.ruby-forum.com/.

Joel Pearson wrote in post #1101267:

Are you really saying that you don't understand the concept of one
number being higher than another?! Try it for yourself in IRB!
And all this after saying "The whole topic is understood by me." about
blocks and parenthetical parsing!

What does it mean by `too high` or `too low` ? I didn't understand the
line.

···

--
Posted via http://www.ruby-forum.com/\.

Language problems here. Not worth getting worked up over imho.

···

On Tue, Mar 12, 2013 at 1:40 PM, Love U Ruby <lists@ruby-forum.com> wrote:

@Scott.

yes I do here it ia:

>> s = "hello"
=> "hello"
>> s["e"] = "u"
=> "u"
>> s
=> "hullo"

The answer to the line **a too-high or too-low numerical index **

>> str = 'aaa'
=> "aaa"
>> str[-4] = "x"
IndexError: index -4 out of string
        from (irb):57:in `='
        from (irb):57
        from C:/Ruby193/bin/irb:12:in `<main>'
>> str[-5] = "x"
IndexError: index -5 out of string
        from (irb):58:in `='
        from (irb):58
        from C:/Ruby193/bin/irb:12:in `<main>'
>> str[4] = "x"
IndexError: index 4 out of string
        from (irb):59:in `='
        from (irb):59
        from C:/Ruby193/bin/irb:12:in `<main>'

Actually that word `too big` and `too small` made me to think too much..
lollzzzzzzz.

Guys if my understanding with the line is wrong then please correct me.

--
Posted via http://www.ruby-forum.com/\.

--
vizualize.me/cliffrosson

Think of this:

a = A.new
a.class #=> A
a.class.ancestors #=> [A, Object, Kernel, BasicObject]
a.is_a? Object #=> true
a.is_a? Module #=> false

A.class #=> Class
A.class.ancestors #=> [Class, Module, Object, Kernel, BasicObject]
A.is_a? Object #=> true
A.is_a? Module #=> true

So x.ancestors means "list of classes and modules x extends/includes" and
y.class.ancestors means "list of classes and modules y.is_a? or
y.instance_of?"

This question should be in a separate thread.

···

On Mar 15, 2013 11:42 PM, "Love U Ruby" <lists@ruby-forum.com> wrote:

Hi,

I have some confusion with "ancestor" method.

Can you help me out to clear the concept?

class A
end

A.ancestors # => [A, Object, Kernel, BasicObject] <~~ Here why came? I
actually expect the output as below one.

A.class.ancestors # => [Class, Module, Object, Kernel, BasicObject]

Sent from my phone, so excuse the typos.

Love U Ruby wrote in post #1101762:

Hi,

class A
end

A.ancestors # => [A, Object, Kernel, BasicObject]

My question is - how does `A` come in the output of `A.ancestors` ?

···

--
Posted via http://www.ruby-forum.com/\.

Dude really?? You don't understand how a String has positions for each character, and how you can supply a number, that corresponds to possible positions, that is either too high or too low?

WHEN are you going to do some actual studying? WHEN are you going to stop nickel and diming this damned list with all of these stupid questions that are answerable with

A) COMMON FRIGGIN SENSE!
B) Google and reading the documentation (such as on Strings)

This is getting ridiculous and I'm REALLY getting tired of seeing these crappy assed questions that shows BLATANTLY that you're neither paying attention to what people tell you, nor reading the documentation and really attempting to understand. NOR are you actually READING the output from irb and trying to understand it. You just dump to the list with Oh, I didn't IMMEDIATELY understand what happened, I'm not going to take the time TO understand it, I'll just dump it to the list and let THEM understand it FOR me! Yeah, thats what I'll do!

Now you're just being lazy, and consequently, stupid.

···

Love U Ruby <mailto:lists@ruby-forum.com>
March 12, 2013 3:56 PM

What does it mean by `too high` or `too low` ? I didn't understand the
line.

Joel Pearson <mailto:lists@ruby-forum.com>
March 12, 2013 3:51 PM
Are you really saying that you don't understand the concept of one
number being higher than another?! Try it for yourself in IRB!
And all this after saying "The whole topic is understood by me." about
blocks and parenthetical parsing!

--
D. Deryl Downey

  "The bug which you would fright me with I seek" - William Shakespeare - The Winter's Tale, Act III, Scene II - A court of Justice.

Language problems here. Not worth getting worked up over imho.

I disagree, considering the by now hundreds(!) of pointless,
unreflected, confused posts.

Instead of helping people with real problems, too many people
--myself included, sadly enough-- waste their time with these
endlessly dragged on discussions over banalities.

···

Am 12.03.2013 21:44, schrieb Cliff Rosson:

On Tue, Mar 12, 2013 at 1:40 PM, Love U Ruby <lists@ruby-forum.com > <mailto:lists@ruby-forum.com>> wrote:

    @Scott.

    yes I do here it ia:

     >> s = "hello"
    => "hello"
     >> s["e"] = "u"
    => "u"
     >> s
    => "hullo"

    The answer to the line **a too-high or too-low numerical index **

     >> str = 'aaa'
    => "aaa"
     >> str[-4] = "x"
    IndexError: index -4 out of string
             from (irb):57:in `='
             from (irb):57
             from C:/Ruby193/bin/irb:12:in `<main>'
     >> str[-5] = "x"
    IndexError: index -5 out of string
             from (irb):58:in `='
             from (irb):58
             from C:/Ruby193/bin/irb:12:in `<main>'
     >> str[4] = "x"
    IndexError: index 4 out of string
             from (irb):59:in `='
             from (irb):59
             from C:/Ruby193/bin/irb:12:in `<main>'

    Actually that word `too big` and `too small` made me to think too much..
    lollzzzzzzz.

    Guys if my understanding with the line is wrong then please correct me.

    --
    Posted via http://www.ruby-forum.com/\.

--
vizualize.me/cliffrosson <http://vizualize.me/cliffrosson&gt;

--
<https://github.com/stomar/&gt;

Based on my previous samples:

a.is_a? A #=> true
A.is_a? A #=> false

The first is true because A.ancestors.include? A

You can also do this:

def decl cls
  cls.ancestors.reverse.inject do |p,c|
    puts "class #{c} < #{p}"
    puts 'end'
  end
end
decl A

Note: I've ignored included modules.

···

On Mar 16, 2013 7:10 AM, "Love U Ruby" <lists@ruby-forum.com> wrote:

Love U Ruby wrote in post #1101762:
> Hi,
>

> class A
> end
>
> A.ancestors # => [A, Object, Kernel, BasicObject]

My question is - how does `A` come in the output of `A.ancestors` ?

Sent from my phone, so excuse the typos.

Hahaha. 2 days into subscribing to this list and I'm already happy I did.

Love U Ruby, I'm new to Ruby and have only been studying it for a week or
so. Have you tried Ruby tutorials on youtube? I'm also learning from the
Programming Ruby book on the website. Also looks like Larry U.'s book on
Ruby is highly recommended on Amazon for beginners- I plan on getting a
copy of that as well.

···

On Tue, Mar 12, 2013 at 4:03 PM, D. Deryl Downey <me@daviddwdowney.com>wrote:

Dude really?? You don't understand how a String has positions for each
character, and how you can supply a number, that corresponds to possible
positions, that is either too high or too low?

WHEN are you going to do some actual studying? WHEN are you going to stop
nickel and diming this damned list with all of these stupid questions that
are answerable with

A) COMMON FRIGGIN SENSE!
B) Google and reading the documentation (such as on Strings)

This is getting ridiculous and I'm REALLY getting tired of seeing these
crappy assed questions that shows BLATANTLY that you're neither paying
attention to what people tell you, nor reading the documentation and really
attempting to understand. NOR are you actually READING the output from irb
and trying to understand it. You just dump to the list with Oh, I didn't
IMMEDIATELY understand what happened, I'm not going to take the time TO
understand it, I'll just dump it to the list and let THEM understand it FOR
me! Yeah, thats what I'll do!

Now you're just being lazy, and consequently, stupid.

  Love U Ruby <lists@ruby-forum.com>
March 12, 2013 3:56 PM

What does it mean by `too high` or `too low` ? I didn't understand the
line.

  Joel Pearson <lists@ruby-forum.com>
March 12, 2013 3:51 PM
Are you really saying that you don't understand the concept of one
number being higher than another?! Try it for yourself in IRB!
And all this after saying "The whole topic is understood by me." about
blocks and parenthetical parsing!

--
D. Deryl Downey

"The bug which you would fright me with I seek" - William Shakespeare -
The Winter's Tale, Act III, Scene II - A court of Justice.

--
Aghori Shaivite

www.aghoriverse.com
aghorishaivite.deviantart.com
agorasphere.blogspot.com

What usually happens is you guys respond in haste, usually with an angry
tone. He figures it out on his own, despite the responses, by finally
stumbling through it in IRB 30 minutes later. Why not just ignore him?
Force him to fart around in IRB until he answers his own question? This
would, in part, clean up some of the negative tone that has plagued the
list recently.

···

On Tue, Mar 12, 2013 at 2:44 PM, <sto.mar@web.de> wrote:

Am 12.03.2013 21:44, schrieb Cliff Rosson:

Language problems here. Not worth getting worked up over imho.

I disagree, considering the by now hundreds(!) of pointless,
unreflected, confused posts.

Instead of helping people with real problems, too many people
--myself included, sadly enough-- waste their time with these
endlessly dragged on discussions over banalities.

On Tue, Mar 12, 2013 at 1:40 PM, Love U Ruby <lists@ruby-forum.com >> <mailto:lists@ruby-forum.com>> wrote:

    @Scott.

    yes I do here it ia:

     >> s = "hello"
    => "hello"
     >> s["e"] = "u"
    => "u"
     >> s
    => "hullo"

    The answer to the line **a too-high or too-low numerical index **

     >> str = 'aaa'
    => "aaa"
     >> str[-4] = "x"
    IndexError: index -4 out of string
             from (irb):57:in `='
             from (irb):57
             from C:/Ruby193/bin/irb:12:in `<main>'
     >> str[-5] = "x"
    IndexError: index -5 out of string
             from (irb):58:in `='
             from (irb):58
             from C:/Ruby193/bin/irb:12:in `<main>'
     >> str[4] = "x"
    IndexError: index 4 out of string
             from (irb):59:in `='
             from (irb):59
             from C:/Ruby193/bin/irb:12:in `<main>'

    Actually that word `too big` and `too small` made me to think too
much..
    lollzzzzzzz.

    Guys if my understanding with the line is wrong then please correct
me.

    --
    Posted via http://www.ruby-forum.com/\.

--
vizualize.me/cliffrosson <http://vizualize.me/**cliffrosson&lt;http://vizualize.me/cliffrosson&gt;
>

--
<https://github.com/stomar/&gt;

--
vizualize.me/cliffrosson

Yes, even after saying you won't waste your time anymore... so why do you?

I've said I'm done with this person... and I am. I suggest you join me.

···

On Mar 12, 2013, at 14:44 , sto.mar@web.de wrote:

Instead of helping people with real problems, too many people
--myself included, sadly enough-- waste their time with these
endlessly dragged on discussions over banalities.

Matthew Kerwin wrote in post #1101845:

You can also do this:

Argh, I couldn't let it sit there so wrong.

def decl cls
   cls.ancestors.reverse.inject do |p,c|
     puts "class #{c} < #{p}"
     puts 'end'
     c # <<<
   end
end
decl A

···

--
Posted via http://www.ruby-forum.com/\.

Ryan Davis wrote in post #1101335:

Instead of helping people with real problems, too many people
--myself included, sadly enough-- waste their time with these
endlessly dragged on discussions over banalities.

Yes, even after saying you won't waste your time anymore... so why do
you?

···

On Mar 12, 2013, at 14:44 , sto.mar@web.de wrote:

--
Posted via http://www.ruby-forum.com/\.