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