Class: Klases::Argset

Inherits:
Object
  • Object
show all
Defined in:
lib/klases/argset.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ Argset



5
6
7
8
9
# File 'lib/klases/argset.rb', line 5

def initialize(*args, &block)
  @options = args.options!
  @args = args
  @block = block
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



11
12
13
# File 'lib/klases/argset.rb', line 11

def args
  @args
end

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/klases/argset.rb', line 11

def options
  @options
end

Instance Method Details

#[](index) ⇒ Object



13
14
15
# File 'lib/klases/argset.rb', line 13

def [](index)
  args[index]
end

#args_and_optionsObject



36
37
38
# File 'lib/klases/argset.rb', line 36

def args_and_options
  @options ? [*@args, @options] : @args
end

#before(*args) ⇒ Object



27
28
29
# File 'lib/klases/argset.rb', line 27

def before(*args)
  self.dup.before!(*args)
end

#before!(*args) ⇒ Object



31
32
33
34
# File 'lib/klases/argset.rb', line 31

def before!(*args)
  @args = args + @args
  self
end

#block(block = false) ⇒ Object



17
18
19
20
# File 'lib/klases/argset.rb', line 17

def block(block = false)
  return @block if block == false
  self.dup.block!(block)
end

#block!(block) ⇒ Object



22
23
24
25
# File 'lib/klases/argset.rb', line 22

def block!(block)
  @block = block
  self
end

#send_to(receiver, method) ⇒ Object



40
41
42
# File 'lib/klases/argset.rb', line 40

def send_to(receiver, method)
  receiver.__send__(method, *args_and_options, &@block)
end

#sizeObject



44
45
46
# File 'lib/klases/argset.rb', line 44

def size
  args.size
end