[RFC] 'via' proposal

  • Thread starter Elias Athanasopoulos
  • Start date
E

Elias Athanasopoulos

Hello!

Well, just a thought... Consider that:

1000.times do |a, b, c|
a = ...
b = ...
c = ...
bar a
bar b
bar c
foo
end

Okay, this is a bad design, but let's say that I can't change
it. Can a Ruby syntax structure like the one below constructed
in an (almost) easy way?

via bar foo do |a, b, c|
a = ...
b = ...
c = ...
end

i.e. can I construct in pure Ruby or via a C extension a 'via'
method for Object, which will enhance:

foo do { |...| ... }

in a way, that all block arguments will be passed in another
method before the end of the block?

If all these do not make sense, just forgive me. It's night
here. :)

Regards,
 
R

Ryan Pavlik

Hello!

Well, just a thought... Consider that:

1000.times do |a, b, c|
a = ...
b = ...
c = ...
bar a
bar b
bar c
foo
end

Okay, this is a bad design, but let's say that I can't change
it.

I'm not sure what's "bad design" about it... there's not really enough
to tell what you're actually doing. If you want fewer lines, you can
always:

1000.times { |a, b, c|
a = bar(...)
b = bar(...)
c = bar(...)
foo
}

Fewer lines or more lines isn't directly related to how good or bad a
design is though.
Can a Ruby syntax structure like the one below constructed
in an (almost) easy way?

via bar foo do |a, b, c|
a = ...
b = ...
c = ...
end
If all these do not make sense, just forgive me. It's night
here. :)

I really can't tell what you're trying to do here... please provide
more details about the actual problem at hand: what you're doing, what
you're trying to accomplish in the end (not just how you're trying to
accomplish it). My guess is there's an easier way.

To answer your question, though, you can always write a function that
takes a block as a parameter. However, you can't directly manipulate
the code inside; otoh, I'm guessing you don't really need to.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,142
Messages
2,570,819
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top