From: Rodrigo Rosenfeld Rosas Date: 2011-07-10T23:10:02+09:00 Subject: [ruby-core:37966] [Ruby 1.9 - Feature #5010] Add Slop(-like) in stdlib and deprecate current OptionParser API Issue #5010 has been updated by Rodrigo Rosenfeld Rosas. Sorry, I still didn't get it. I understand that you don't want any DSL when you talk about instance_eval, right? Any reason why you find it confusing, since this is a common pattern when writing DSL's in Ruby? I mean, is there some real example showing how this could be confusing? Anyway, if that's the concern, Slop also support this alternative:
opts = Slop.parse do |s|
  s.banner "Usage: example.rb [options]"
  s.on :v, :verbose, "Run verbosely", :default => true
end
I don't really care about using instance_eval or not, but I still find that the OptionParser API could be better written. ---------------------------------------- Feature #5010: Add Slop(-like) in stdlib and deprecate current OptionParser API http://redmine.ruby-lang.org/issues/5010 Author: Rodrigo Rosenfeld Rosas Status: Open Priority: Low Assignee: Yukihiro Matsumoto Category: Target version: 2.0 I always found the OptionParser API not as well designed as it could be. I've just found this gem: http://lee.jarvis.co/slop/ Much better API and I think we should integrate it to Ruby 2.0. Take a look at the minimal example shown in OptionParser :
  require 'optparse'

  options = {}
  OptionParser.new do |opts|
    opts.banner = "Usage: example.rb [options]"

    opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
      options[:verbose] = v
    end
  end.parse!

  p options
  p ARGV
This is the equivalent in Slop:
require 'slop'

opts = Slop.parse do
  banner "Usage: example.rb [options]"
  on :v, :verbose, "Run verbosely", :default => true
end

p opts.to_hash
-- http://redmine.ruby-lang.org