Class: Torch::Argv::Flags

Inherits:
Delegator
  • Object
show all
Defined in:
lib/torch/argv.rb

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Flags

Returns a new instance of Flags.



35
36
37
38
# File 'lib/torch/argv.rb', line 35

def initialize(argv)
  @argv = argv
  super
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_sym, *arguments, &block) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/torch/argv.rb', line 65

def method_missing(method_sym, *arguments, &block)
  if method_sym.to_s =~ /^_([a-zA-Z0-9_]+)\?$/
    return include? $1
  else
    super
  end
end

Instance Method Details

#__getobj__Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/torch/argv.rb', line 47

def __getobj__
  @flags ||= @argv.select{|arg| arg[0,1] == '-'}.map do |arg|
    if arg[0..1] == '--'
      arg[2..-1]
    else
      arg[1..-1].split(//)
    end
  end.flatten
  return @flags
end

#__setobj__(obj) ⇒ Object

We don’t allow this



44
45
# File 'lib/torch/argv.rb', line 44

def __setobj__(obj) # We don't allow this
end

#include?(flag) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/torch/argv.rb', line 40

def include?(flag)
  return super(flag.to_s)
end

#respond_to?(method_sym, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
61
62
63
64
# File 'lib/torch/argv.rb', line 58

def respond_to?(method_sym, include_private = false)
  if method_sym.to_s =~ /^_([a-zA-Z0-9_]+)\?$/
    return true
  else
    return super
  end
end