Feature #5011
closedAdd Perl 6-like main method definition support: accept command-line arguments as method arguments
Description
Take a look at this:
http://perlgeek.de/en/article/5-to-6#post_14
I'm not really sure how this would look like in Ruby, but I like the idea of defining a main method could extract their params from command-line params.
This would also be an alternative for issue #4824:
Files
Updated by naruse (Yui NARUSE) about 13 years ago
- Project changed from Ruby master to 14
- Target version deleted (
3.0)
Updated by naruse (Yui NARUSE) about 13 years ago
- Project changed from 14 to Ruby master
Updated by shyouhei (Shyouhei Urabe) over 12 years ago
- Status changed from Open to Assigned
Updated by rosenfeld (Rodrigo Rosenfeld Rosas) over 12 years ago
- File feature-5011.odp feature-5011.odp added
Updated by mame (Yusuke Endoh) over 12 years ago
Received.
Your proposal is interesting, but slightly vague.
I understand motivation, but not the detailed behavior.
If you tolerate the details, I guess you can do it with gem, without modifying ruby interpreter.
[load_main.rb]
at_exit do
if respond_to?(:main, true) && method(:main).source_location[0] == $0
options = {}
# parse command line options...
main(ARGF, **options)
end
end
[bar.rb]
def main(input)
p :bar
end
[foo1.rb]
require "bar"
def main(input, opt)
p :foo1
end
[foo2.rb]
require "bar"
$ ruby -rload_main foo1.rb
:foo
$ ruby -rload_main foo2.rb
--
Yusuke Endoh mame@tsg.ne.jp
Updated by rosenfeld (Rodrigo Rosenfeld Rosas) over 12 years ago
Not sure if it is that simple as I would need some way of extracting the argument names and default values from the method. How can I do that?
Anyway, this certainly requires much more discussion about the details on how to design that. I'm more concerned with the overall idea. I don't really care about the exact details on how this would work as long as parsing arguments could be made much easier, like in Perl 6...
I'll try to make some experiment this weekend by parsing the source line in some simple way for demonstrating purposes of the overall idea... Maybe you could provide me some implementation for querying the arguments and default values in ruby-head, than I could install it with RVM and try it without any hack like parsing the source itself...
Updated by mame (Yusuke Endoh) over 12 years ago
- Status changed from Assigned to Rejected
Rodrigo Rosenfeld Rosas,
Sorry but this proposal was rejected at the developer meeting (7/21).
Matz said that it was not a bad idea to improve optparse, but that
this proposal was not in the right direction.
--
Yusuke Endoh mame@tsg.ne.jp
Updated by rosenfeld (Rodrigo Rosenfeld Rosas) over 12 years ago
Great, I'll love to see when the right direction appear ;)