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 a ‘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



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

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



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

alias_method :Flag_old, :Flag

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



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

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



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

alias_method :Option_old, :Option