What is the meaning of line?: if !in_quotes || in_quotes[@parsers[:stray_quote]] at line approx 1643 in faster_csv.rb
on 2012-08-09 13:32
on 2012-08-09 14:25
!in_quotes => if in_quotes is nil or false
in_quotes[....] => calls the #[] method on in_quotes with the given
argument
So this is effectively saying:
if in_quotes[@parsers[:stray_quote]]
but with a get-out clause which avoids the line bombing out if in_quotes
is nil.
on 2012-08-09 17:19
> in_quotes[....] => calls the #[] method on in_quotes with the given > argument Is this functional programming? If so or even if I am wrong, kindly help me with some pointer to understand it betetr and have better grip on RUBY!
on 2012-08-10 09:22
> in_quotes[....] => calls the #[] method on in_quotes with the given
What is #[] method?
on 2012-08-10 09:33
Hi, ajay paswan wrote in post #1071826: >> in_quotes[....] => calls the #[] method on in_quotes with the given >> argument > > Is this functional programming? What do you mean by "functional programming"? As to the usual meaning of the word: no. ajay paswan wrote in post #1071904: >> in_quotes[....] => calls the #[] method on in_quotes with the given > > What is #[] method? It is the method that you define by def [](...) ... end and call by your_object[...] It's the "indexing method" known from arrays: arr = [1, 2, 3] puts arr[0] # <-- this calls the "[]" method of the Array class
on 2012-08-10 15:21
Jan E. wrote in post #1071905: > arr = [1, 2, 3] > puts arr[0] # <-- this calls the "[]" method of the Array class Exactly. In this case, because ruby is a dynamic language, what precisely it does depends on what objects @parsers and in_quotes represent at runtime. So you need to work back through the code to find where they are set. At a guess, I would say @parsers is quite likely to be a Hash. If that's true, @parsers[:stray_quote] will get you the Hash value whose key is the symbol :stray_quote. >> parsers = {:fluffy=>123, :wombat=>456} => {:fluffy=>123, :wombat=>456} >> parsers[:fluffy] => 123 >> parsers[:wombat] => 456 But this isn't necessarily so; @parsers could be any object which implements a [] method. >> saytwice = lambda { |x| x + x } => #<Proc:0x0000000101c2b6c0@(irb):9> >> saytwice["hello"] => "hellohello"
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
Log in with Google account | Log in with Yahoo account
No account? Register here.