| Module | IRB::ExtendCommandBundle |
| In: |
lib/irb/ext/use-loader.rb
lib/irb/extend-command.rb |
IRB extended command
| EXCB | = | ExtendCommandBundle |
| NO_OVERRIDE | = | 0 |
| OVERRIDE_PRIVATE_ONLY | = | 0x01 |
| OVERRIDE_ALL | = | 0x02 |
aliases = [commans_alias, flag], …
# File lib/irb/extend-command.rb, line 116
116: def self.def_extend_command(cmd_name, cmd_class, load_file = nil, *aliases)
117: case cmd_class
118: when Symbol
119: cmd_class = cmd_class.id2name
120: when String
121: when Class
122: cmd_class = cmd_class.name
123: end
124:
125: if load_file
126: eval %[
127: def #{cmd_name}(*opts, &b)
128: require "#{load_file}"
129: eval %[
130: def #{cmd_name}(*opts, &b)
131: ExtendCommand::#{cmd_class}.execute(irb_context, *opts, &b)
132: end
133: ]
134: send :#{cmd_name}, *opts, &b
135: end
136: ]
137: else
138: eval %[
139: def #{cmd_name}(*opts, &b)
140: ExtendCommand::#{cmd_class}.execute(irb_context, *opts, &b)
141: end
142: ]
143: end
144:
145: for ali, flag in aliases
146: @ALIASES.push [ali, cmd_name, flag]
147: end
148: end
# File lib/irb/extend-command.rb, line 175
175: def self.extend_object(obj)
176: unless (class<<obj;ancestors;end).include?(EXCB)
177: super
178: for ali, com, flg in @ALIASES
179: obj.install_alias_method(ali, com, flg)
180: end
181: end
182: end
# File lib/irb/extend-command.rb, line 109
109: def self.install_extend_commands
110: for args in @EXTEND_COMMANDS
111: def_extend_command(*args)
112: end
113: end
# File lib/irb/extend-command.rb, line 171
171: def self.irb_original_method_name(method_name)
172: "irb_" + method_name + "_org"
173: end
override = {NO_OVERRIDE, OVERRIDE_PRIVATE_ONLY, OVERRIDE_ALL}
# File lib/irb/extend-command.rb, line 151
151: def install_alias_method(to, from, override = NO_OVERRIDE)
152: to = to.id2name unless to.kind_of?(String)
153: from = from.id2name unless from.kind_of?(String)
154:
155: if override == OVERRIDE_ALL or
156: (override == OVERRIDE_PRIVATE_ONLY) && !respond_to?(to) or
157: (override == NO_OVERRIDE) && !respond_to?(to, true)
158: target = self
159: (class<<self;self;end).instance_eval{
160: if target.respond_to?(to, true) &&
161: !target.respond_to?(EXCB.irb_original_method_name(to), true)
162: alias_method(EXCB.irb_original_method_name(to), to)
163: end
164: alias_method to, from
165: }
166: else
167: print "irb: warn: can't alias #{to} from #{from}.\n"
168: end
169: end
# File lib/irb/extend-command.rb, line 23
23: def irb_exit(ret = 0)
24: irb_context.exit(ret)
25: end
# File lib/irb/ext/use-loader.rb, line 23
23: def irb_load(*opts, &b)
24: ExtendCommand::Load.execute(irb_context, *opts, &b)
25: end