[#407882] Ruby extremely slow compared to PHP — Mick Jagger <lists@...>

Hello there, how are you? Hope you are fine. I am a PHP programmer

17 messages 2013/06/02

[#407908] TCPServer/Socket and Marshal problem — Panagiotis Atmatzidis <atma@...>

Hello,

18 messages 2013/06/03

[#407946] Is rubyquiz.com dead? — Alphonse 23 <lists@...>

Thread title says everything.

18 messages 2013/06/04

[#408012] Need help understanding recursion. — pedro oliva <lists@...>

Ive been reading Chris Pine's book 'Learn to Program' and its been going

11 messages 2013/06/06

[#408129] Getting Started With Development — Chamila Wijayarathna <cdwijayarathna@...>

I'm new to Ruby Development. I downloaded source from Github, but couldn't

24 messages 2013/06/11
[#408131] Re: Getting Started With Development — Per-erik Martin <lists@...> 2013/06/11

Ruby is often installed on linux, or can be easily installed with the

[#408146] Re: Getting Started With Development — "Chamila W." <lists@...> 2013/06/11

Per-erik Martin wrote in post #1112021:

[#408149] Re: Getting Started With Development — "Carlo E. Prelz" <fluido@...> 2013/06/11

Subject: Re: Getting Started With Development

[#408198] NokoGiri XML Parser — "Devender P." <lists@...>

Hi,

11 messages 2013/06/13

[#408201] trying to load a .rb file in irb — "Eric D." <lists@...>

I am trying to load a ruby program into irb and it will not load.

12 messages 2013/06/13

[#408205] Can I use Sinatra to render dynamic pages? — Ruby Student <ruby.student@...>

Hell Team,

18 messages 2013/06/13
[#408219] Re: Can I use Sinatra to render dynamic pages? — Nicholas Van Weerdenburg <vanweerd@...> 2013/06/14

You should be able to do this without JavaScript by using streaming.

[#408228] Re: Can I use Sinatra to render dynamic pages? — Ruby Student <ruby.student@...> 2013/06/14

Well, I got some good suggestions from everyone here. I thank you all for

[#408275] Compare and sort one array according to another. — masta Blasta <lists@...>

I have two arrays of objects that look something like this:

14 messages 2013/06/17

[#408276] Comparing objects — "Thom T." <lists@...>

How do I compare two objects in Ruby, considering only attributes

15 messages 2013/06/17

[#408307] getting the most out of Ruby — robin wood <lists@...>

I write a lot of scripts in Ruby, most are small simple things but some

13 messages 2013/06/18

[#408309] Creating ruby script exe — Rochit Sen <lists@...>

Hi All,

17 messages 2013/06/18

[#408357] Beginners problem with database and datamapper — cristian cristian <lists@...>

Hi all!

28 messages 2013/06/20

[#408437] How do I input a variable floating point number into Ruby Programs — "Michael P F." <lists@...>

I want to evaluate the following interactively:

10 messages 2013/06/23

[#408518] #!/usr/bin/env: No such file or directory — Todd Sterben <lists@...>

I am new to both linux and ruby. I am using Ubuntu and Ruby 1.9

17 messages 2013/06/27

[#408528] Designing a Cabinet class — Mike Vezzani <lists@...>

Hello all,

12 messages 2013/06/27

[#408561] Find elment in array of hashes — Rodrigo Lueneberg <lists@...>

array = {:id=>1, :price =>0.25} # index[0]

23 messages 2013/06/28

Re: Is it a bug(about constant reference on dynamic class).

From: Tamara Temple <tamouse.lists@...>
Date: 2013-06-01 22:28:22 UTC
List: ruby-talk #407866
jin chizhong <lists@ruby-forum.com> wrote:
> When I use a dynamic class, It can not reference constants.
> See follow code and remark.
> And is there any way to work around it?
> 
> #!/usr/bin/env ruby
> 
> class T
>   def hello
>     puts self.class.constants.join " "    # right, AAA
>     puts AAA                              # right, 1
>   end
> end
> 
> T::AAA = 1
> 
> t = T.new
> t.hello
> 
> 
> c = Class.new do
>   def hello
>     puts self.class.constants.join " "    # right, AAA
>     puts AAA          # error: uninitialized constant AAA (NameError)
>   end
> end
> 
> c::AAA = 123
> inst = c.new
> inst.hello
> 
> -- 
> Posted via http://www.ruby-forum.com/.
> 

ENOTABUG :)

(for in-depth, read "Metaprogramming Ruby")

When you do t = T.new, you are getting something different than when you
do inst = c.new:

irb(main):039:0> class T;def hello;puts self.class.constants.join " ";puts T_0; end; end
=> nil
irb(main):040:0> t=T.new
=> #<T:0x9f1bb6c>
irb(main):041:0> t.hello

NameError: uninitialized constant T::T_0
	from (irb):39:in `hello'
	from (irb):41
	from /home/tamara/.rvm/rubies/ruby-1.9.3-p392/bin/irb:13:in `<main>'
irb(main):042:0> T::T_0 = "This is now set"
=> "This is now set"
irb(main):043:0> t.hello
T_0
This is now set
=> nil



and now using the Class object:

irb(main):002:0> c = Class.new{def hello;p self.class.constants; p self.class.const_get("C_0");end}
=> #<Class:0x89ef2ac>
irb(main):003:0> c0 = c.new
=> #<#<Class:0x89ef2ac>:0x89ed3e4>
irb(main):004:0> c0.hello
[]
NameError: uninitialized constant #<Class:0x89ef2ac>::C_0
	from (irb):2:in `const_get'
	from (irb):2:in `hello'
	from (irb):4
	from /home/tamara/.rvm/rubies/ruby-1.9.3-p392/bin/irb:13:in `<main>'
irb(main):005:0> c0.class.const_set("C_0","this is now set")
=> "this is now set"
irb(main):006:0> c0.hello
[:C_0]
"this is now set"
=> "this is now set"
irb(main):007:0> c0.class.const_set("C_1","this is another class constant")
=> "this is another class constant"
irb(main):008:0> c0.hello
[:C_0, :C_1]
"this is now set"
=> "this is now set"
irb(main):009:0> c0.class.const_get("C_1")
=> "this is another class constant"
irb(main):010:0> 


The main thing to note is the extra level of indirection in the second
case:

irb(main):040:0> t=T.new
=> #<T:0x9f1bb6c>

Notice in this case the named type T, vs here:

irb(main):003:0> c0 = c.new
=> #<#<Class:0x89ef2ac>:0x89ed3e4>

the indirection, thus the main difference in ruby's syntactic ability to
deal with things.

Doing this:

T::T_0 = 'sommat'

is under the hood doing the same thing above:

irb(main):025:0> class T;def hello;p self.class.constants; p T_0;end;end
=> nil
irb(main):026:0> T.new.hello
[]
NameError: uninitialized constant T::T_0
	from (irb):25:in `hello'
	from (irb):26
	from /home/tamara/.rvm/rubies/ruby-1.9.3-p392/bin/irb:13:in `<main>'
irb(main):027:0> T.const_set("T_0","set via const_set")
=> "set via const_set"
irb(main):028:0> T.new.hello
[:T_0]
"set via const_set"
=> "set via const_set"
irb(main):029:0> T::T_0 = "set via T::"
(irb):29: warning: already initialized constant T_0
=> "set via T::"
irb(main):030:0> T.new.hello
[:T_0]
"set via T::"
=> "set via T::"



In This Thread