[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[ANN] Article: An Exercise in Metaprogramming with Ruby

rubyhacker

3/24/2006 7:37:00 PM

I failed to post this link before, so here it is now:

http://www.devsource.com/article2/0,1895,1928...

My editor said it "didn't do that well" in terms of page views. And I
said,
well, I should have posted it to ruby-talk. And she said: Do that now,
and we'll see what effect it has.

So there you have it. No bots or artificial inflation, please. ;)

This article, by the way, was adapted from a talk given in January
to the Austin on Rails group.


Cheers,
Hal

15 Answers

matthew.moss.coder

3/24/2006 7:53:00 PM

0

Interesting article... just about the level I needed. A decent
example, not uselessly trivial, but not terribly complex either, so I
can follow enough of the metaprogramming to truly understand what's
going on.

Thanks...


On 3/24/06, rubyhacker@gmail.com <rubyhacker@gmail.com> wrote:
> I failed to post this link before, so here it is now:
>
> http://www.devsource.com/article2/0,1895,1928...
>
> My editor said it "didn't do that well" in terms of page views. And I
> said,
> well, I should have posted it to ruby-talk. And she said: Do that now,
> and we'll see what effect it has.
>
> So there you have it. No bots or artificial inflation, please. ;)
>
> This article, by the way, was adapted from a talk given in January
> to the Austin on Rails group.
>
>
> Cheers,
> Hal
>
>
>


John W. Long

3/24/2006 8:03:00 PM

0

Hal wrote:
> I failed to post this link before, so here it is now:
>
> http://www.devsource.com/article2/0,1895,1928...
>

Wow. Very nice. I'm doing a fair amount of meta programing myself these
days and having resources like this for reference and information is great.

I like the way you dynamically create the class using Object#const_set.
Metaprogramming sure beats generating code the traditional way.

--
John Long
http://wiseheart...


pat eyler

3/24/2006 8:13:00 PM

0

On 3/24/06, rubyhacker@gmail.com <rubyhacker@gmail.com> wrote:
> I failed to post this link before, so here it is now:
>
> http://www.devsource.com/article2/0,1895,1928...
>
> My editor said it "didn't do that well" in terms of page views. And I
> said,
> well, I should have posted it to ruby-talk. And she said: Do that now,
> and we'll see what effect it has.

Nice article Hal. It's a shame ZD requires registration to comment
there though.

>
> So there you have it. No bots or artificial inflation, please. ;)


I'll be sharing it around at work, just a bit of natural inflation :)

>
> This article, by the way, was adapted from a talk given in January
> to the Austin on Rails group.
>
>
> Cheers,
> Hal
>
>
>


--
thanks,
-pate
-------------------------


James Gray

3/24/2006 8:28:00 PM

0

On Mar 24, 2006, at 1:38 PM, rubyhacker@gmail.com wrote:

> I failed to post this link before, so here it is now:
>
> http://www.devsource.com/article2/0,1895,1928...

That's so darn cool, I think I'm just going to have to add it to
FasterCSV... ;)

Excellent article Hal!

James Edward Gray II


Bill Guindon

3/24/2006 8:49:00 PM

0

On 3/24/06, Matthew Moss <matthew.moss.coder@gmail.com> wrote:
> Interesting article... just about the level I needed. A decent
> example, not uselessly trivial, but not terribly complex either, so I
> can follow enough of the metaprogramming to truly understand what's
> going on.

+1

Great stuff Hal, thanks much.

> Thanks...
>
>
> On 3/24/06, rubyhacker@gmail.com <rubyhacker@gmail.com> wrote:
> > I failed to post this link before, so here it is now:
> >
> > http://www.devsource.com/article2/0,1895,1928...
> >
> > My editor said it "didn't do that well" in terms of page views. And I
> > said,
> > well, I should have posted it to ruby-talk. And she said: Do that now,
> > and we'll see what effect it has.
> >
> > So there you have it. No bots or artificial inflation, please. ;)
> >
> > This article, by the way, was adapted from a talk given in January
> > to the Austin on Rails group.
> >
> >
> > Cheers,
> > Hal
> >
> >
> >
>
>


--
Bill Guindon (aka aGorilla)
The best answer to most questions is "it depends".


Ernest Obusek

3/24/2006 10:07:00 PM

0

I'm a Ruby newbie. So far I am loving everything I learn about
Ruby. I'm trying to find a real app to create with it. I have need
for a client program that talks to an LDAP server and that makes
calls to an ONC/RPC server that we wrote here at my job in C++. Do
these exist for Ruby?

Thanks!

Ernest



Keith Sader

3/25/2006 2:30:00 AM

0

Question along these lines, suppose you add an attribute to the
'People' class after the initial creation (say by adding another
column to the people.txt file), do the 'old' people classes get the
new attribute as well? If so, what's the initial value? I suspect it
would be nil.

thanks,

On 3/24/06, John W. Long <ng@johnwlong.com> wrote:
> Hal wrote:
> > I failed to post this link before, so here it is now:
> >
> > http://www.devsource.com/article2/0,1895,1928...
> >
>
> Wow. Very nice. I'm doing a fair amount of meta programing myself these
> days and having resources like this for reference and information is great.
>
> I like the way you dynamically create the class using Object#const_set.
> Metaprogramming sure beats generating code the traditional way.
>
> --
> John Long
> http://wiseheart...
>
>


--
Keith Sader
ksader@gmail.com
http://www.saderfamily.org/roller/p...


Andrew Johnson

3/25/2006 2:55:00 AM

0

Of course, un-pedagogically, it could be compressed a tad:

class DataRecord

def self.make(file_name)
header = File.open(file_name){|f|f.gets}.split(/,/)
struct = File.basename(file_name,'.txt').capitalize
record = Struct.new(struct, *header)

class<<record;self;end.send :define_method, :read do
File.open(file_name) do |f|
f.gets
f.inject([]){|a,l| a << record.new(*eval("[#{l}]")) }
end
end

record
end

end

data = DataRecord.make('people.txt')
list = data.read # or: Struct::People.read
person = list[2]
puts person.name
if person.age < 18
puts "under 18"
else
puts "over 18"
end
puts "Weight is: %.2f kg" % kg = person.weight / 2.2

cheers,
andrew

--
Andrew L. Johnson http://www.s...
What have you done to the cat? It looks half-dead.
-- Schroedinger's wife

benjohn

3/25/2006 11:39:00 AM

0


On 24 Mar 2006, at 19:38, rubyhacker@gmail.com wrote:

> I failed to post this link before, so here it is now:
>
> http://www.devsource.com/article2/0,1895,1928...

Thanks very much, you've inspired me to clean up some crusty code
I've been ignoring for a while!


Meinrad Recheis

3/25/2006 11:43:00 AM

0

On 3/24/06, rubyhacker@gmail.com <rubyhacker@gmail.com> wrote:
> I failed to post this link before, so here it is now:
>
> http://www.devsource.com/article2/0,1895,1928...
>
[...]

i like the article!

yeah, and even if code using the fields is coupled tightly to the
created classes, the solution is highly reusable.
-- henon