Forum: Ruby Confusion with Strings

Posted by Love U Ruby (my-ruby)
on 2013-03-12 20:25
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 by Joel Pearson (virtuoso)
on 2013-03-12 20:51
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 by Love U Ruby (my-ruby)
on 2013-03-12 20:55
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 by D. Deryl Downey (ddd)
on 2013-03-12 21:03
Attachment: compose-unknown-contact.jpg (770 Bytes)
(Received via mailing list)
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.


> 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.
Posted by Scott McGinness (Guest)
on 2013-03-12 21:33
(Received via mailing list)
On 12 March 2013 19:25, Love U Ruby <lists@ruby-forum.com> wrote:

>
> --
> 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.
Posted by Love U Ruby (my-ruby)
on 2013-03-12 21:40
@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 by Cliff Rosson (beaon)
on 2013-03-12 21:45
(Received via mailing list)
Language problems here. Not worth getting worked up over imho.
Posted by unknown (Guest)
on 2013-03-12 22:45
(Received via mailing list)
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.
Posted by Aghori Shaivite (Guest)
on 2013-03-12 22:49
Attachment: compose-unknown-contact.jpg (770 Bytes)
(Received via mailing list)
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:

>
>
> 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
Posted by Cliff Rosson (beaon)
on 2013-03-12 22:51
(Received via mailing list)
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.
Posted by Ryan Davis (Guest)
on 2013-03-13 05:28
(Received via mailing list)
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.

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.
Posted by Matthew Kerwin (mattyk)
on 2013-03-13 06:40
Ryan Davis wrote in post #1101335:
>
> 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.
>
> Yes, even after saying you won't waste your time anymore... so why do
> you?

http://xkcd.com/386/
Posted by Joel Pearson (virtuoso)
on 2013-03-13 08:37
For some reason the page won't load for me :/ I'll just assume it's the 
one about someone being wrong on the internet.
Posted by Love U Ruby (my-ruby)
on 2013-03-15 14:41
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 by Matthew Kerwin (mattyk)
on 2013-03-15 21:35
(Received via mailing list)
On Mar 15, 2013 11:42 PM, "Love U Ruby" <lists@ruby-forum.com> wrote:
> 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]

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.

Sent from my phone, so excuse the typos.
Posted by Love U Ruby (my-ruby)
on 2013-03-15 22:09
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 by Matthew Kerwin (mattyk)
on 2013-03-15 22:26
(Received via mailing list)
On Mar 16, 2013 7:10 AM, "Love U Ruby" <lists@ruby-forum.com> wrote:
> My question is - how does `A` come in the output of `A.ancestors` ?
>

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.

Sent from my phone, so excuse the typos.
Posted by Matthew Kerwin (mattyk)
on 2013-03-16 01:20
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
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.