Hi
In short:
class A
def b
33
puts 99, b
end
end
p A.new.b
No error?!
Seems printed b is a local var.
How can I call the method b (inside def)? (Maybe there should be an if
anywhere)
Thx
Berg
Hi
In short:
class A
def b
33
puts 99, b
end
end
p A.new.b
No error?!
Seems printed b is a local var.
How can I call the method b (inside def)? (Maybe there should be an if
anywhere)
Thx
Berg
Why returns "stack level too deep (SystemStackError)" ?
2016-08-07 8:09 GMT-04:30 Borja Gª de Vinuesa <borjavinuessa@gmail.com>:
Hi!
I guess you meant (note you missed defining variable 'b'):
Local variable
class A
def b
b = 33
puts 99, b
end
end
p A.new.b[image: Mixmax] <https://mixmax.com/r/M223xLQTWSziRaxPi> Not
using Mixmax yet? <https://mixmax.com/r/M223xLQTWSziRaxPi>In this case, puts calls 'b' local variable. In case you want to call b
method, you have to call it with 'self':Calling self
class A
def b
b = 33
puts 99, self.b
end
end
p A.new.b
# => stack level too deep (SystemStackError)[image: Mixmax] <https://mixmax.com/r/M223xLQTWSziRaxPi> Not
using Mixmax yet? <https://mixmax.com/r/M223xLQTWSziRaxPi>On Sun, Aug 7, 2016 2:14 PM, A Berger aberger7890@gmail.com wrote:
Hi
In short:class A
def b
33
puts 99, b
end
endp A.new.b
No error?!
Seems printed b is a local var.
How can I call the method b (inside def)? (Maybe there should be an if
anywhere)
Thx
BergBorja García de Vinuesa O.
Gemfeed <http://www.gemfeed.com/> | ePolitic <http://www.epolitic.org/>
Linkedin <https://es.linkedin.com/in/borjagvo> | Twitter
<https://twitter.com/BorjaGVO>
(34) 609 166 517 | Skype <http://borjagarciadevinuesa.blogspot.com/>Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
Hi!
I guess you meant (note you missed defining variable 'b'):
Local variableclassAdefbb=33puts99, bendendpA.new.b
Not using Mixmax yet?
In this case, puts calls 'b' local variable. In case you want to call b method,
you have to call it with 'self':
Calling selfclassAdefbb=33puts99, self.bendendpA.new.b# => stack level too deep (SystemStackError)
Not using Mixmax yet?
On Sun, Aug 7, 2016 2:14 PM, A Berger aberger7890@gmail.com wrote:
Hi
In short:
class A
def b
33
puts 99, b
end
end
p A.new.b
No error?!
Seems printed b is a local var.
How can I call the method b (inside def)? (Maybe there should be an if anywhere)
Thx
Berg
Borja García de Vinuesa O. Gemfeed | ePolitic Linkedin | Twitter (34) 609 166 517 | Skype
Creates never stopable recursion.
On Sun, Aug 7, 2016 2:43 PM, Nerio Navea neriojose5@gmail.com wrote:
Why returns " stack level too deep (SystemStackError)" ?
2016-08-07 8:09 GMT-04:30 Borja Gª de Vinuesa < borjavinuessa@gmail.com > :
Hi!
I guess you meant (note you missed defining variable 'b'):
Local variableclassAdefbb=33puts99, bendendpA.new.b
Not using Mixmax yet?
In this case, puts calls 'b' local variable. In case you want to call b method,
you have to call it with 'self':
Calling selfclassAdefbb=33puts99, self.bendendpA.new.b# => stack level too deep (SystemStackError)
Not using Mixmax yet?
On Sun, Aug 7, 2016 2:14 PM, A Berger aberger7890@gmail.com wrote:
Hi
In short:
class A
def b
33
puts 99, b
end
end
p A.new.b
No error?!
Seems printed b is a local var.
How can I call the method b (inside def)? (Maybe there should be an if anywhere)
Thx
Berg
Borja García de Vinuesa O. Gemfeed | ePolitic Linkedin | Twitter (34) 609 166 517 | Skype
Unsubscribe: <mailto: ruby-talk-request@ ruby-lang.org ?subject= unsubscribe>
< http://lists.ruby-lang.org/ cgi-bin/mailman/options/ruby- talk >
Borja García de Vinuesa O. Gemfeed | ePolitic Linkedin | Twitter (34) 609 166 517 | Skype
Hi
No, that was intended -
how can I then distinguish between (calling) class an object methods?
Why is there now error shown for undefined b (and x2) ?
class A
def b
33
puts 99, b
end
end
#puts x1 ## would be an error
puts A.new.b
puts x2 ## no error? Seems never reached?!!
Thanks Berg
2016-08-07 15:14, A Berger написав:
Hi
In short:class A
def b
33
puts 99, b
endp A.new.b
No error?!
Seems printed b is a local var.
How can I call the method b (inside def)? (Maybe there should be an if
anywhere)
Thx
BergUnsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
Hi,
It's recursion, in your example. Recursion - Wikipedia
If you try this,
def b
33
b = 45 #here initialization of local variable.
puts 99,b
puts "Object id of local b is #{b.object_id}"
end
b.object_id
now b in def b is a local variable. Look at object_id!
Have a nice day =)
Hi
No, that was intended -
how can I then distinguish between (calling) class an object methods?Why is there now error shown for undefined b (and x2) ?
Because b is not undefined. Plus, the check is made at calltime - not
when the method is defined:
irb(main):008:0> class X; def a; b; end end
=> :a
irb(main):009:0> X.new.a
NameError: undefined local variable or method `b' for #<X:0x0000000158b7d0>
from (irb):8:in `a'
from (irb):9
from /usr/bin/irb:11:in `<main>'
And, as you can see, if there is no variable a method is assumed.
Hence the error message.
class A
def b
33
puts 99, b
end
end#puts x1 ## would be an error
puts A.new.b
puts x2 ## no error? Seems never reached?!!
Because of the recursion that ends with an exception. Do you actually
READ the error messages you get? They are there for a reason.
robert
On Sun, Aug 7, 2016 at 2:51 PM, A Berger <aberger7890@gmail.com> wrote:
--
[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can
- without end}
http://blog.rubybestpractices.com/
I do not see what relevance the object_id has. It is not attached to
the variable. What is your reasoning?
Kind regards
robert
On Sun, Aug 7, 2016 at 9:40 PM, nuncostans <nuncostans@vivaldi.net> wrote:
It's recursion, in your example. Recursion - Wikipedia
If you try this,
def b
33
b = 45 #here initialization of local variable.
puts 99,b
puts "Object id of local b is #{b.object_id}"
end
b.object_idnow b in def b is a local variable. Look at object_id!
--
[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can
- without end}
http://blog.rubybestpractices.com/
Hi
I shouldnt use Ruboto irb any more:
class A
def b
33
puts 99, b
end
end
#puts x1 ## would be an error
puts A.new.b
puts x2 ## no error? Seems never reached?!!
Because of the recursion that ends with an exception. Do you actually
READ the error messages you get? They are there for a reason.
The output is nil with no error. Therefore the question, why there's no
error msg.
- I didnt expect there were such big differences to (/bugs in) Ruboto.
Sorry I didnt had the possibility running it with MRI.
Berg
If ruboto does clever tail recursion you're probably just entering an
infinite loop in 'b'.
Cheers
On 10/08/2016, A Berger <aberger7890@gmail.com> wrote:
Hi
I shouldnt use Ruboto irb any more:class A
def b
33
puts 99, b
end
end#puts x1 ## would be an error
puts A.new.b
puts x2 ## no error? Seems never reached?!!Because of the recursion that ends with an exception. Do you actually
READ the error messages you get? They are there for a reason.The output is nil with no error. Therefore the question, why there's no
error msg.
- I didnt expect there were such big differences to (/bugs in) Ruboto.
Sorry I didnt had the possibility running it with MRI.Berg
--
Matthew Kerwin
http://matthew.kerwin.net.au/
which version of ruby and platform did you use? I get `stack level too deep
(SystemStackError)` error on my machine (ruby 2.3.1p112 (2016-04-26
revision 54768) [x86_64-darwin15])
Matthew Kerwin <matthew@kerwin.net.au>于2016年8月10日周三 上午5:39写道:
On 10/08/2016, A Berger <aberger7890@gmail.com> wrote:
> Hi
> I shouldnt use Ruboto irb any more:
>
> class A
> def b
> 33
> puts 99, b
> end
> end
>
> #puts x1 ## would be an error
> puts A.new.b
> puts x2 ## no error? Seems never reached?!!
>
>>
>> Because of the recursion that ends with an exception. Do you actually
>> READ the error messages you get? They are there for a reason.
>
> The output is nil with no error. Therefore the question, why there's no
> error msg.
> - I didnt expect there were such big differences to (/bugs in) Ruboto.
> Sorry I didnt had the possibility running it with MRI.
>
> Berg
>If ruboto does clever tail recursion you're probably just entering an
infinite loop in 'b'.Cheers
--
Matthew Kerwin
http://matthew.kerwin.net.au/Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
Hi
Im using
RUBY_VERSION
1.9.3
JRUBY_VERSION
1.7.19
thx, Berg
Am 26.08.2016 04:28 schrieb "timlen tse" <tinglenxan@gmail.com>:
which version of ruby and platform did you use? I get `stack level too
deep (SystemStackError)` error on my machine (ruby 2.3.1p112 (2016-04-26
revision 54768) [x86_64-darwin15])Matthew Kerwin <matthew@kerwin.net.au>于2016年8月10日周三 上午5:39写道:
On 10/08/2016, A Berger <aberger7890@gmail.com> wrote:
> Hi
> I shouldnt use Ruboto irb any more:
>
> class A
> def b
> 33
> puts 99, b
> end
> end
>
> #puts x1 ## would be an error
> puts A.new.b
> puts x2 ## no error? Seems never reached?!!
>
>>
>> Because of the recursion that ends with an exception. Do you actually
>> READ the error messages you get? They are there for a reason.
>
> The output is nil with no error. Therefore the question, why there's no
> error msg.
> - I didnt expect there were such big differences to (/bugs in) Ruboto.
> Sorry I didnt had the possibility running it with MRI.
>
> Berg
>If ruboto does clever tail recursion you're probably just entering an
infinite loop in 'b'.Cheers
--
Matthew Kerwin
http://matthew.kerwin.net.au/Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>