Class: CLASP

Inherits:
Object
  • Object
show all
Defined in:
lib/libclimate/climate.rb

Overview

We monkey-patch CLASP module’s Flag and Option generator methods by added in an action attribute (but only if it does not exist) and attaching the given block

Class Method Summary collapse

Class Method Details

.Flag(name, options = {}, &blk) ⇒ Object

Defines a flag, attaching the given block



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/libclimate/climate.rb', line 75

def Flag(name, options={}, &blk)

	f = self.Flag_old(name, options)

	# anticipate this functionality being added to CLASP
	return f if f.respond_to? :action

	class << f

		attr_accessor :action
	end

	if blk

		case blk.arity
		when 0, 1, 2
		else

			warn "wrong arity for flag"
		end

		f.action = blk
	end

	f
end

.Flag_oldObject

:nodoc:



71
# File 'lib/libclimate/climate.rb', line 71

alias_method :Flag_old, :Flag

.Option(name, options = {}, &blk) ⇒ Object

Defines an option, attaching the given block



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/libclimate/climate.rb', line 103

def Option(name, options={}, &blk)

	o = self.Option_old(name, options)

	# anticipate this functionality being added to CLASP
	return o if o.respond_to? :action

	class << o

		attr_accessor :action
	end

	if blk

		case blk.arity
		when 0, 1, 2
		else

			warn "wrong arity for option"
		end

		o.action = blk
	end

	o
end

.Option_oldObject

:nodoc:



72
# File 'lib/libclimate/climate.rb', line 72

alias_method :Option_old, :Option