This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[63] pry(main)> Pokemon.battle(Pokemon::PIKACHU, Pokemon::PIKACHU) | |
The moves avalible for pokemon #1 are: | |
Thundershock | Growl | Tail Whip | Thunder Wave | |
1 | |
The moves avalible for pokemon #2 are: | |
Thundershock | Growl | Tail Whip | Thunder Wave | |
3 | |
Pikachu is attacking Pikachu for 20 HP with Thundershock | |
Pikachu is attacking Pikachu for 0 HP with Tail_Whip | |
=> -25 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Pry::Commands.create_command "find" do | |
description "Recursively search a Module/Class for a method : find [REGEX] [MODULE/CLASS]" | |
def process | |
regex = eval "/#{args[0..-2].join(' ')}/" | |
base = ::Class.const_get args.last | |
ret = search(regex, base) | |
output.puts ret.flatten | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Pry::Commands.create_command "find-method" do | |
description "find-method: Find a method recursively USAGE: find-method [OPTION] [REGEX] [BASECLASS]" | |
def options(opti) | |
#method_options(opti) | |
opti.on :n, :name, "Search for a method by name" | |
opti.on :c, :content, "Search for a method based on content in Regex form" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[111] pry(main)> class Tester | |
[111] pry(main)* def test_method | |
[111] pry(main)* geewhiz = 1 | |
[111] pry(main)* end | |
[111] pry(main)* end | |
=> nil | |
[112] pry(main)> find-method -c 'gee.+' Tester | |
Tester#test_method |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Pry::Commands.create_command "find-method" do | |
description "find-method" | |
def options(opti) | |
opti.on :n, :name, "Search for a method by name" | |
opti.on :c, :content, "Search for a method based on content in Regex form" | |
end | |
def process |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Pry::Commands.create_command "find-method" do | |
description "find-method" | |
def options(opti) | |
opti.on :n, :name, "Search for a method by name" | |
opti.on :c, :content, "Search for a method based on content in Regex form" | |
end | |
def process |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def dist(size, n) | |
m = size % n | |
d = (n-m) % size | |
([d]*(n-m)) + ([1]*(m)) | |
end | |
p dist(10, 12) | |
# [2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def dist(size, n) | |
m = size % n | |
d = (n-m) % size | |
([d]*(n-m)) + ([1]*(m)) | |
end | |
p dist(10, 12) | |
# [2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[1] pry(main)> load "./hack.rb" | |
/usr/local/lib/ruby/gems/1.9.1/gems/reg-0.4.8/regdeferred.rb:53: warning: undefining `object_id' may cause serious problems | |
/usr/local/lib/ruby/gems/1.9.1/gems/reg-0.4.8/regdeferred.rb:53: warning: undefining `object_id' may cause serious problems | |
/usr/local/lib/ruby/gems/1.9.1/gems/reg-0.4.8/regdeferred.rb:53: warning: undefining `object_id' may cause serious problems | |
/usr/local/lib/ruby/gems/1.9.1/gems/reg-0.4.8/regdeferred.rb:53: warning: undefining `object_id' may cause serious problems | |
/usr/local/lib/ruby/gems/1.9.1/gems/reg-0.4.8/regdeferred.rb:53: warning: undefining `object_id' may cause serious problems | |
^[[A=> true | |
[2] pry(main)> Pry.add_hack(:method, Pry::Hackage::Hack.new(/^\@([A-Za-z0-9_]+)$/) { replace_with "instance_variable_get(:@#{capture 1})" }) | |
=> 28680540 | |
[3] pry(main)> class Test; def initialize; @o = 1; end; end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[1] pry(main)> load "./hack.rb"; Pry.config.hack.enabled = true | |
=> true | |
[2] pry(main)> Pry.add_hack(:%, :symbol_array, Pry::Hackage::ModOpHack.new('S') { replace_with "%w#{capture 1}#{capture 2}#{capture 3}.map(&:to_sym)" }) | |
=> #<Pry::Hackage::ModOpHack:0x00000001081140 | |
@CHAR="S", | |
@CODE=#<Proc:0x00000001088f80@(pry):2>> | |
[3] pry(main)> %S{hello symbol world! i bet everyone is jealous of pry now} | |
=> [:hello, :symbol, :world!, :i, :bet, :everyone, :is, :jealous, :of, :p |
OlderNewer