[#349422] Date.parse('17:26:33 Oct 31, 2009') returns invalid date — Jacob Gorban <jacob.gorban@...>

Hi,

13 messages 2009/11/01

[#349519] All Gems Down? — Joshua Ballanco <jballanc@...>

I think I must be the only one using allgems.ruby-forum.com. It seems

17 messages 2009/11/03

[#349527] Ruby Inline over two times slower under 1.9 than under 1.8? — "Shot (Piotr Szotkowski)" <shot@...>

I=E2=80=99m starting to dip my toes in non-Ruby coding (for performance rea=

13 messages 2009/11/03
[#349564] Re: Ruby Inline over two times slower under 1.9 than under 1.8? — Ryan Davis <ryand-ruby@...> 2009/11/03

[#350186] Re: Ruby Inline over two times slower under 1.9 than under 1.8? — "Shot (Piotr Szotkowski)" <shot@...> 2009/11/11

Ryan Davis:

[#350196] Re: Ruby Inline over two times slower under 1.9 than under 1.8? — Roger Pack <rogerpack2005@...> 2009/11/11

> — Shot, who’s off to play with RubyToC now. :)

[#350228] Re: Ruby Inline over two times slower under 1.9 than under 1.8? — "Shot (Piotr Szotkowski)" <shot@...> 2009/11/11

Roger Pack:

[#349640] Odd : a = Hash.new(Hash.new) — Aldric Giacomoni <aldric@...>

irb(main):086:0> a = Hash.new(Hash.new)

13 messages 2009/11/04
[#349641] Re: Odd : a = Hash.new(Hash.new) — Aldric Giacomoni <aldric@...> 2009/11/04

Aldric Giacomoni wrote:

[#349685] Create HTML files using RUBY — Krithika San <skrithikaa@...>

Hi,

23 messages 2009/11/04
[#349690] Re: Create HTML files using RUBY — Marnen Laibow-Koser <marnen@...> 2009/11/04

Krithika San wrote:

[#349691] Re: Create HTML files using RUBY — Krithika San <skrithikaa@...> 2009/11/04

Hi Marnen,

[#349692] Re: Create HTML files using RUBY — Marnen Laibow-Koser <marnen@...> 2009/11/04

Krithika San wrote:

[#349720] Executing one of several ruby objects — "dhf0820@..." <dhf0820@...>

I am trying to write a program that will load a series of DSLs (ruby

11 messages 2009/11/05

[#349849] RCR enumerable extra into core — Roger Pack <rogerpack2005@...>

I'm considering suggesting that the base functionality for the

25 messages 2009/11/08
[#349853] Re: RCR enumerable extra into core — "David A. Black" <dblack@...> 2009/11/08

Hi --

[#349996] Re: RCR enumerable extra into core — Roger Pack <rogerpack2005@...> 2009/11/09

[#349888] Using Nokogiri — jzakiya <jzakiya@...>

I'm trying to scrape some data off websites using nokogiri

18 messages 2009/11/08

[#349926] FileString - request for comments — apeiros@...

Hi there

15 messages 2009/11/09
[#349931] Re: FileString - request for comments — James Edward Gray II <james@...> 2009/11/09

On Nov 8, 2009, at 7:47 PM, apeiros@gmx.net wrote:

[#349987] Berkeley DB BDB Install on Windows — david <davidhooey@...>

I've been scripting in Ruby (and Rails) for about two years now, but

14 messages 2009/11/09

[#350007] Good or best way to allocate a large array — Ralph Shnelvar <ralphs@...32.com>

Newbie here:

45 messages 2009/11/09
[#350017] Re: Good or best way to allocate a large array — Marnen Laibow-Koser <marnen@...> 2009/11/09

Ralph Shnelvar wrote:

[#350019] Re: Good or best way to allocate a large array — Ralph Shnelvar <ralphs@...32.com> 2009/11/09

Marnen,

[#350023] Re: Good or best way to allocate a large array — Marnen Laibow-Koser <marnen@...> 2009/11/09

Ralph Shnelvar wrote:

[#350029] Re: Good or best way to allocate a large array — Ralph Shnelvar <ralphs@...32.com> 2009/11/09

Marnen,

[#350042] Re: Good or best way to allocate a large array — "Florian Frank" <flori@...> 2009/11/09

Ralph Shnelvar wrote:

[#350045] Re: Good or best way to allocate a large array — Ralph Shnelvar <ralphs@...32.com> 2009/11/09

Florian,

[#350047] Re: Good or best way to allocate a large array — Rick DeNatale <rick.denatale@...> 2009/11/09

On Mon, Nov 9, 2009 at 5:46 PM, Ralph Shnelvar <ralphs@dos32.com> wrote:

[#350048] Re: Good or best way to allocate a large array — Ralph Shnelvar <ralphs@...32.com> 2009/11/10

Rick,

[#350053] Re: Good or best way to allocate a large array — Florian Gilcher <flo@...> 2009/11/10

Hi,

[#350142] Calling a subprocess with specific arguments and capturing its output? — Dan Q <quinxex@...>

Hi. I haven't written Ruby in a while, and I was wondering if someone

9 messages 2009/11/10

[#350147] Roman Numerals (Arrgh!) — Rick Barrett <chngth3wrld@...>

I have a homework assignment where I have to convert an inputted integer

22 messages 2009/11/10
[#350150] Re: Roman Numerals (Arrgh!) — Rob Biedenharn <Rob@...> 2009/11/11

On Nov 10, 2009, at 6:56 PM, Rick Barrett wrote:

[#350152] Re: Roman Numerals (Arrgh!) — Gennady Bystritsky <Gennady.Bystritsky@...> 2009/11/11

On Nov 10, 2009, at 5:37 PM, Rob Biedenharn wrote:

[#350156] Re: Roman Numerals (Arrgh!) — Rob Biedenharn <Rob@...> 2009/11/11

On Nov 10, 2009, at 8:49 PM, Gennady Bystritsky wrote:

[#350159] Re: Roman Numerals (Arrgh!) — Gennady Bystritsky <Gennady.Bystritsky@...> 2009/11/11

[#350290] DRYing a Regex — RichardOnRails <RichardDummyMailbox58407@...>

I've got a routine that works fine at building an array of upper-case

42 messages 2009/11/12
[#350311] Re: DRYing a Regex — RichardOnRails <RichardDummyMailbox58407@...> 2009/11/13

On Nov 12, 6:50=A0pm, James Edward Gray II <ja...@graysoftinc.com>

[#350367] Naming conventions -- was: Re: DRYing a Regex — Marnen Laibow-Koser <marnen@...> 2009/11/14

RichardOnRails wrote:

[#350368] Re: Naming conventions -- was: Re: DRYing a Regex — James Edward Gray II <james@...> 2009/11/14

On Nov 13, 2009, at 10:11 PM, Marnen Laibow-Koser wrote:

[#350369] Re: Naming conventions -- was: Re: DRYing a Regex — Marnen Laibow-Koser <marnen@...> 2009/11/14

James Edward Gray II wrote:

[#350415] Re: Naming conventions -- was: Re: DRYing a Regex — "David A. Black" <dblack@...> 2009/11/14

Hi --

[#350426] Re: Naming conventions -- was: Re: DRYing a Regex — Marnen Laibow-Koser <marnen@...> 2009/11/14

David A. Black wrote:

[#350359] Trajectories — Thijs Leeflang <t_leeflang@...>

hello,

60 messages 2009/11/13
[#350444] Re: Trajectories — Marnen Laibow-Koser <marnen@...> 2009/11/14

Thijs Leeflang wrote:

[#350446] Re: Trajectories — Eleanor McHugh <eleanor@...> 2009/11/15

On 14 Nov 2009, at 23:40, Marnen Laibow-Koser wrote:

[#350447] Re: Trajectories — Marnen Laibow-Koser <marnen@...> 2009/11/15

Eleanor McHugh wrote:

[#350449] Re: Trajectories — Eleanor McHugh <eleanor@...> 2009/11/15

On 15 Nov 2009, at 00:42, Marnen Laibow-Koser wrote:

[#350451] Re: Trajectories — Marnen Laibow-Koser <marnen@...> 2009/11/15

Eleanor McHugh wrote:

[#350509] Re: Trajectories — Rick DeNatale <rick.denatale@...> 2009/11/15

On Sat, Nov 14, 2009 at 8:19 PM, Marnen Laibow-Koser <marnen@marnen.org> wr=

[#350523] Re: Trajectories — Marnen Laibow-Koser <marnen@...> 2009/11/15

Rick Denatale wrote:

[#350524] Re: Trajectories — Eleanor McHugh <eleanor@...> 2009/11/15

On 15 Nov 2009, at 23:02, Marnen Laibow-Koser wrote:

[#350529] Re: Trajectories — Todd Benson <caduceass@...> 2009/11/16

On Sun, Nov 15, 2009 at 5:32 PM, Eleanor McHugh

[#350532] Re: Trajectories — Eleanor McHugh <eleanor@...> 2009/11/16

On 16 Nov 2009, at 01:12, Todd Benson wrote:

[#350538] Re: Trajectories — Marnen Laibow-Koser <marnen@...> 2009/11/16

Eleanor McHugh wrote:

[#350577] Re: Trajectories — Paul Smith <paul@...> 2009/11/16

On Mon, Nov 16, 2009 at 2:57 AM, Marnen Laibow-Koser <marnen@marnen.org> wr=

[#350593] Re: Trajectories — Marnen Laibow-Koser <marnen@...> 2009/11/16

Paul Smith wrote:

[#350600] Re: Trajectories — Paul Smith <paul@...> 2009/11/16

On Mon, Nov 16, 2009 at 3:18 PM, Marnen Laibow-Koser <marnen@marnen.org> wrote:

[#350602] Re: Trajectories — Marnen Laibow-Koser <marnen@...> 2009/11/16

Paul Smith wrote:

[#350628] Re: Trajectories — Caleb Clausen <vikkous@...> 2009/11/17

On 11/16/09, Marnen Laibow-Koser <marnen@marnen.org> wrote:

[#350629] Re: Trajectories — Marnen Laibow-Koser <marnen@...> 2009/11/17

Caleb Clausen wrote:

[#350645] Re: Trajectories — Caleb Clausen <vikkous@...> 2009/11/17

On 11/16/09, Marnen Laibow-Koser <marnen@marnen.org> wrote:

[#350454] How do I get a random number between two random numbers? — Alex Untitled <somebodydc691n@...>

I want to create a program that asks you to guess a number between two

12 messages 2009/11/15

[#350476] Traversing the contents of a proc (for a DSL) — Siemen Baader <siemenbaader@...>

Hi List,

11 messages 2009/11/15

[#350485] Using activerecord with mysql — Rob Mauchel <rmauchel@...>

Hi All,

13 messages 2009/11/15

[#350526] Newbie question: Defining a numeric type — Seebs <usenet-nospam@...>

I have a type which has a bit of internal magic, but fundamentally, I want

32 messages 2009/11/16

[#350535] Any official name for Ruby's class which makes "class methods"? — Hunt Jon <jona.hunt777@...>

We all know Ruby really doesn't have class methods.

20 messages 2009/11/16
[#350539] Re: Any official name for Ruby's class which makes "class me — Marnen Laibow-Koser <marnen@...> 2009/11/16

Hunt Jon wrote:

[#350682] Re: Any official name for Ruby's class which makes "class me — "David A. Black" <dblack@...> 2009/11/17
[#350689] Re: Any official name for Ruby's class which makes "class me — Marnen Laibow-Koser <marnen@...> 2009/11/17

David A. Black wrote:

[#350698] Re: Any official name for Ruby's class which makes "class me — "David A. Black" <dblack@...> 2009/11/17

[#350590] Google Wave: A new type of "Ruby Quiz" ? — Aldric Giacomoni <aldric@...>

Google Wave is, according to Google, "the new email". It combines email,

21 messages 2009/11/16

[#350594] something went wrong — Dev Tri <divyanshutri@...>

16 messages 2009/11/16

[#350669] What is the difference between the two following pieces of c — Doney Kaka <doneysr@...>

Don't really know where to go with this one, but I gotta know...

10 messages 2009/11/17

[#350679] Class inside a Method Body — Mike Stephens <rubfor@...>

I have a class that works fine if I declare it outside of anything. If

15 messages 2009/11/17

[#350705] Special characters in csv header using fastercsv — John Mcleod <john.mcleod@...>

Hello all,

17 messages 2009/11/17
[#350709] Re: Special characters in csv header using fastercsv — James Edward Gray II <james@...> 2009/11/17

On Nov 17, 2009, at 10:24 AM, John Mcleod wrote:

[#350710] Re: Special characters in csv header using fastercsv — John Mcleod <john.mcleod@...> 2009/11/17

James,

[#350712] Re: Special characters in csv header using fastercsv — James Edward Gray II <james@...> 2009/11/17

On Nov 17, 2009, at 10:38 AM, John Mcleod wrote:

[#350719] Re: Special characters in csv header using fastercsv — John Mcleod <john.mcleod@...> 2009/11/17

I'm not sure if the placement is correct but I'm still getting "Error

[#350810] Exact (LISP-ish) calculations in Ruby? — Aldric Giacomoni <aldric@...>

Has anyone written a gem for exact calculations? The kind one would find

25 messages 2009/11/18

[#350829] Ruby/tk Help Please — Sean Ob <sob4ever33@...>

I am a complete beginner when it comes to programming and i need some

20 messages 2009/11/18
[#350830] Re: Ruby/tk Help Please — Marnen Laibow-Koser <marnen@...> 2009/11/18

Sean Ob wrote:

[#350924] How to strip ruby comments in a ruby line of code? — Alexandre Mutel <alexandre_mutel@...>

Short description : My question is : do you know any available method,

17 messages 2009/11/19

[#350969] Re-opening an existing module and changing a method — Aldric Giacomoni <aldric@...>

"I hear and I forget; I see and I remember; I do and I understand."

11 messages 2009/11/19

[#351010] RubyForge gem index is no more — Tom Copeland <tom@...>

Hello -

14 messages 2009/11/20

[#351084] Distinct Sets (#225) — Daniel Moore <yahivin@...>

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

21 messages 2009/11/21
[#351111] Re: [QUIZ] Distinct Sets (#225) — brabuhr@... 2009/11/21

On Fri, Nov 20, 2009 at 9:23 PM, Daniel Moore <yahivin@gmail.com> wrote:

[#351170] Re: [QUIZ] Distinct Sets (#225) — Rob Biedenharn <Rob@...> 2009/11/22

[#351171] Re: Distinct Sets (#225) — lith <minilith@...> 2009/11/22

> http://gist.github.com/240457

[#351279] Re: Distinct Sets (#225) — Rob Biedenharn <Rob@...> 2009/11/23

On Nov 22, 2009, at 1:51 AM, lith wrote:

[#351137] Order of evaluation and precedence — Seebs <usenet-nospam@...>

In _The Ruby Programming Language_, it is asserted that order of evaluation

11 messages 2009/11/21

[#351245] More on psuedo arrays; Better way? — Ralph Shnelvar <ralphs@...32.com>

Newbie here:

15 messages 2009/11/23
[#351266] Re: More on psuedo arrays; Better way? — Marnen Laibow-Koser <marnen@...> 2009/11/23

Ralph Shnelvar wrote:

[#351267] Re: More on psuedo arrays; Better way? — Brian Candler <b.candler@...> 2009/11/23

Marnen Laibow-Koser wrote:

[#351271] Re: More on psuedo arrays; Better way? — Ralph Shnelvar <ralphs@...32.com> 2009/11/23

BC> Marnen Laibow-Koser wrote:

[#351297] ideas for a "parameter sweep" program? — Diego Virasoro <diego.virasoro@...>

Hello,

11 messages 2009/11/23

[#351328] Warning: instance variable @foo not initialized — Seebs <usenet-nospam@...>

Running some simple tests with Prawn, I am getting thousands of lines

13 messages 2009/11/24

[#351367] Difference between << and += for Strings and Arrays. Bug? — Pieter Hugo <pieter@...>

Hi

14 messages 2009/11/24
[#351373] Re: Difference between << and += for Strings and Arrays. Bug? — Tom Stuart <tom@...> 2009/11/24

2009/11/24 Pieter Hugo <pieter@internext.co.za>:

[#351377] Re: Difference between << and += for Strings and Arrays. Bug? — Pieter Hugo <pieter@...> 2009/11/24

Hi Guys

[#351426] Ruby internals & other questions — Ralph Shnelvar <ralphs@...32.com>

Is there a document or website that describes how Ruby works?

17 messages 2009/11/25

[#351448] Ruby a good choice for CGI? — Nick Dr <nickhannum@...>

Ive been messing around with Ruby for a few weeks now, and I'm fairly

28 messages 2009/11/25
[#351452] Re: Ruby a good choice for CGI? — David Masover <ninja@...> 2009/11/25

On Wednesday 25 November 2009 01:12:19 pm Nick Dr wrote:

[#351453] Re: Ruby a good choice for CGI? — Marnen Laibow-Koser <marnen@...> 2009/11/25

David Masover wrote:

[#351455] Re: Ruby a good choice for CGI? — David Masover <ninja@...> 2009/11/25

On Wednesday 25 November 2009 02:38:32 pm Marnen Laibow-Koser wrote:

[#351456] Re: Ruby a good choice for CGI? — Judson Lester <nyarly@...> 2009/11/25

On Wed, Nov 25, 2009 at 12:52 PM, David Masover <ninja@slaphack.com> wrote:

[#351461] Re: Ruby a good choice for CGI? — David Masover <ninja@...> 2009/11/25

On Wednesday 25 November 2009 03:00:49 pm Judson Lester wrote:

[#351508] Ruby byte access to disk sectors like dd does — Gary Hasson <gary@...>

I have been unable to find any reference to Ruby methods that provide

16 messages 2009/11/26

[#351548] Class variables, instance variables, singleton; Ruby v. C++ — Ralph Shnelvar <ralphs@...32.com>

Newb here coming from C++

31 messages 2009/11/27
[#351570] Re: Class variables, instance variables, singleton; Ruby v. C++ — Steve Wilhelm <steve@...831.com> 2009/11/28

Ralph Shnelvar wrote:

[#351579] Re: Class variables, instance variables, singleton; Ruby v. C++ — "David A. Black" <dblack@...> 2009/11/28

Hi --

[#351586] Re: Class variables, instance variables, singleton; Ruby v. C++ — Ralph Shnelvar <ralphs@...32.com> 2009/11/28

DAB> And of course this is one of the (many) problems with class variables:

[#351572] Local variables can't be accessed from outside, right? — Michael Winterstein <parzival@...>

Hi, I've been trying to figure out metaprogramming and I've mostly got

9 messages 2009/11/28

[#351637] Best way to distribute an app — Omar Campos <hypermeister@...>

Hello everyone,

16 messages 2009/11/29
[#351682] Re: Best way to distribute an app — David Masover <ninja@...> 2009/11/29

On Saturday 28 November 2009 09:03:12 pm Omar Campos wrote:

[#351655] ruby language parser in ruby — Brian Candler <b.candler@...>

I'm looking for a ruby language parser written in ruby, that I can hack

27 messages 2009/11/29

[#351753] have a problem with the loops and variable — Sajjad Po <magicc0d3r@...>

Hi Friends.

20 messages 2009/11/30
[#351756] Re: have a problem with the loops and variable — Michael Linfield <globyy3000@...> 2009/11/30

[#351788] Re: have a problem with the loops and variable — Marnen Laibow-Koser <marnen@...> 2009/12/01

Michael Linfield wrote:

[#351796] Re: have a problem with the loops and variable — Sajjad Po <magicc0d3r@...> 2009/12/01

thank you friends.

[#351798] Re: have a problem with the loops and variable — Sajjad Iran <magicc0d3r@...> 2009/12/01

I want create a program like this.

[#351833] Re: have a problem with the loops and variable — Michael Linfield <globyy3000@...> 2009/12/01

Sajjad Po wrote:

[#351835] Re: have a problem with the loops and variable — Marnen Laibow-Koser <marnen@...> 2009/12/01

Michael Linfield wrote:

[#351840] Re: have a problem with the loops and variable — Michael Linfield <globyy3000@...> 2009/12/01

For something small such as testing lets say a million keys, the

[#351842] Re: have a problem with the loops and variable — Marnen Laibow-Koser <marnen@...> 2009/12/02

Michael Linfield wrote:

[#351755] Problem trying to get a constant with correct scope — Alexandre Mutel <alexandre_mutel@...>

I'm trying to get a constant inside a class (but i have to do it outside

11 messages 2009/11/30

Re: Class variables, instance variables, singleton; Ruby v.

From: David Masover <ninja@...>
Date: 2009-11-28 17:14:14 UTC
List: ruby-talk #351605
On Saturday 28 November 2009 08:43:30 am Ralph Shnelvar wrote:

> >> But see (3), below.
> >>
> >>
> >>
> >> (3)
> >>     class F
> >>       def sub1
> >>         @@x = 1
> >>       end
> >>     end
> >>
> >>     class G
> >>       self.sub1
> >>         @@x=2
> >>       end
> >>     end
> >>
> >>     # Why?  Didn't the interpreter "see" @@x in class F?
> >>     F.class_variables  # []
> 
> MLK> Probably not, since you haven't called the function yet!
> 
> Didn't the interpreter parse it?
> 
> If I do
>   class X
>     def y
>       xyzzy = 3++
>     end
>   end
> 
> then the interpreter/parser will complain immediately that there was a
> syntax error even though the function method y was not executed.

Yes, syntax errors are caught immediately by parsing. But think of instance 
variables as a hash associated with the object and it might be more clear. For 
example, if you did this:

SomeHash = {}
def foo
  SomeHash[:x] = :y
end

Would you expect SomeHash[:x] to exist just because you defined that method?

Now, I don't know whether instance variables are _actually_ implemented as a 
hash. It might well be something much more efficient, but it behaves like a 
hash, so that makes sense.

Also, consider: The method in question may _never_ be called. Why should Ruby 
bother to create a variable that may never be used? That would be just as 
foolish as implying that SomeHash[:x] exists before foo is called in my 
example above. Sure, you could create it and set it to nil, but that'd be 
pointless.

> In C++, instances have access to the static variables and functions of
> the class.
> 
> They don't inherit it ... but merely have access to it as if they
> inherited it.

Instances indeed get access to class variables associated with that instance, 
but again, class variables behave weirdly. But here's a quick example to help 
clarify things:

SomeClass.new

Would you expect an object created that way to have a 'new' method of its own? 
That is, would this make any sense:

SomeClass.new.new

Similarly, do the methods available at class creation time make any sense in 
an object? For example, when creating a class:

class Foo
  attr_accessor :bar
end

You might think attr_accessor is a keyword. It isn't, it's just a method on 
Class, so it's a class method on Foo.

There is no proper analog to "static functions" in C++, by the way -- they're 
just methods on the class. But again, they aren't included into the instance 
-- you access them on the class, just like you would with any other object.

So let me return to some simple examples that I hope make sense. Let's create 
a counter for the number of instances that have been created.

class Foo
  def self.count
    @count
  end
  def self.increment_count
    @count ||= 0
    @count += 1
  end
end

This should be easy to understand. (If it's not, pretend I defined them 
without self, and see if they make sense.)

Now, go define them, and play with them in irb. You wouldn't create any 
instances of Foo yet, but you can do things like this:

Foo.count
Foo.increment_count
Foo.count
Foo.increment_count
Foo.increment_count
Foo.count

Go try that in irb, and see if the result makes sense.

Now let's move on. Keep the same class above, but add this -- if you're in the 
same irb session, you can just re-open the class:

class Foo
  def initialize
    Foo.increment_count
  end
end

Now our counter should work as expected:

Foo.count
f = Foo.new
Foo.count

It won't tell you how many Foo objects actually exist. It's more a count of 
how many have ever been created.

Also, if you understand this so far, go back to my earlier example that was 
"way over your head" -- see if it makes sense. I'll give you an example -- if 
you have a variable f, which is an instance of class Foo, what is f.class?

And if you're inside the initialize method of f, what is self? And what is 
self.class?

> MLK> (There is a way to call private methods from outside, but I will leave
> MLK> you to find it out on your own.  It's not generally a good thing, and
> MLK> I'm not going to hand you a dangerous tool until you understand when
>  not MLK> to use it.)
> 
> So ... when _can_ I use class_variable_get  ???

You can use it whenever you want. When _should_ you use it?

Like instance_variable_get, it's designed for metaprogramming -- that is, when 
you're trying to access a variable, but its name is dynamic.

I'll give you an example of when instance_variable_get might be used. Remember 
attr_reader? (If not, look it up...)  Now, for speed, attr_reader is defined 
in C, but it can be defined in Ruby. Here's the obvious 'eval' solution:

class Module
  def attr_reader *names
    names.each do |name|
      eval "def #{name}; @#{name}; end"
    end
  end
end

But there are many reasons I dislike eval. Here's the solution I'd prefer:

class Module
  def attr_reader *names
    names.each do |name|
      var_name = :"@#{name}"
      define_method name do
        instance_variable_get var_name
      end
    end
  end
end

I don't expect you to follow every detail here. The use of define_method is an 
advanced topic already. Hopefully, though, the fact that you already know how 
to use attr_reader should give you an idea of how that works.

Also, I don't really expect you to need any of this yet -- attr_reader, 
attr_writer, and attr_accessor should already do everything you need.

In This Thread