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 = [commands_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: arity = ExtendCommand::#{cmd_class}.instance_method(:execute).arity 130: args = (1..arity.abs).map {|i| "arg" + i.to_s } 131: args << "*opts" if arity < 0 132: args << "&block" 133: args = args.join(", ") 134: eval %[ 135: def #{cmd_name}(\#{args}) 136: ExtendCommand::#{cmd_class}.execute(irb_context, \#{args}) 137: end 138: ] 139: send :#{cmd_name}, *opts, &b 140: end 141: ] 142: else 143: eval %[ 144: def #{cmd_name}(*opts, &b) 145: ExtendCommand::#{cmd_class}.execute(irb_context, *opts, &b) 146: end 147: ] 148: end 149: 150: for ali, flag in aliases 151: @ALIASES.push [ali, cmd_name, flag] 152: end 153: end
# File lib/irb/extend-command.rb, line 180 180: def self.extend_object(obj) 181: unless (class<<obj;ancestors;end).include?(EXCB) 182: super 183: for ali, com, flg in @ALIASES 184: obj.install_alias_method(ali, com, flg) 185: end 186: end 187: 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 176 176: def self.irb_original_method_name(method_name) 177: "irb_" + method_name + "_org" 178: end
override = {NO_OVERRIDE, OVERRIDE_PRIVATE_ONLY, OVERRIDE_ALL}
# File lib/irb/extend-command.rb, line 156 156: def install_alias_method(to, from, override = NO_OVERRIDE) 157: to = to.id2name unless to.kind_of?(String) 158: from = from.id2name unless from.kind_of?(String) 159: 160: if override == OVERRIDE_ALL or 161: (override == OVERRIDE_PRIVATE_ONLY) && !respond_to?(to) or 162: (override == NO_OVERRIDE) && !respond_to?(to, true) 163: target = self 164: (class<<self;self;end).instance_eval{ 165: if target.respond_to?(to, true) && 166: !target.respond_to?(EXCB.irb_original_method_name(to), true) 167: alias_method(EXCB.irb_original_method_name(to), to) 168: end 169: alias_method to, from 170: } 171: else 172: print "irb: warn: can't alias #{to} from #{from}.\n" 173: end 174: 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