Sha256: beaa77fe562b8c4bb80004340882ae080753d86c72dea10b06de6b0a37952fe4

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

require 'cl'

class SplatLeft < Cl::Cmd
  register 'splat:left'

  arg :one, type: :array
  args :two, :three

  def run
    [self.registry_key, one: one, two: two, three: three]
  end
end

class SplatMiddle < Cl::Cmd
  register 'splat:middle'

  arg :one
  arg :two, type: :array
  arg :three

  def run
    [self.registry_key, one: one, two: two, three: three]
  end
end

class SplatRight < Cl::Cmd
  register 'splat:right'

  args :one, :two
  arg :three, type: :array

  def run
    [self.registry_key, one: one, two: two, three: three]
  end
end

def output(cmd, args)
  args = args.map { |key, value| "#{key}=#{value.inspect}" }.join(' ')
  puts "Called #{cmd} with #{args}"
end

output *Cl.run(*%w(splat left foo bar baz buz))
# Output:
# Called splat:left with one=["foo", "bar"] two="baz" three="buz"

output *Cl.run(*%w(splat middle foo bar baz buz))
# Output:
# Called splat:middle with one="foo" two=["bar", "baz"] three="buz"

output *Cl.run(*%w(splat right foo bar baz buz))
# Output:
# Called splat:middle with one="foo" two="bar" three=["baz", "buz"]

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cl-0.0.4 examples/args/splat.rb
cl-0.0.3 examples/args/splat.rb