html
head
body
This file contains hidden or 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
class FlexiDict(dict, DDispatch): | |
def get_gt(self, key): | |
return [v for k,v in d.iteritems() if k > key] | |
def __getattr__(self, name): | |
if name.startswith("find_"): | |
params = name.split("_") | |
if len(params) == 3: | |
def func(): |
This file contains hidden or 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-debugger git:(master) ✗ bundle exec ruby examples/example_basic.rb | |
/Users/quintessentialbum/src/_projects/debugger/lib/ruby_debug.bundle: warning: already initialized constant VERSION | |
From: examples/example_basic.rb @ line 2 : | |
1: require 'pry' | |
=> 2: binding.pry | |
3: | |
4: a = 2 | |
5: b = 3 |
This file contains hidden or 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
@i = 0 | |
1.upto(100) {|i| @i = i} | |
on ->(frame) { frame.var("i") == 15 } do puts "fizz buzz" end | |
on ->(frame) { frame.var("i") == 3 } do puts "fizz" end | |
on ->(frame) { frame.var("i") == 5 } do puts "buzz" end |
This file contains hidden or 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
# why can a proc be passed to an instance_eval and not a lambda? | |
b = binding | |
b.instance_eval {@x = 5} | |
b.instance_eval &(proc {puts @x}) | |
b.instance_eval &(lambda {puts @x}) |
Users of the command line are familiar with the idea of building pipelines: a chain of simple commands strung together to the output of one becomes the input of the next. Using pipelines and a basic set of primitives, shell users can accomplish some sophisticated tasks. Here's a basic Unix shell pipeline that reports the ten longest .tip files in the current directory, based on the number of lines in each file:
wc -l *.tip | grep \.tip | sort -n | tail -10
Let's see how to add something similar to Ruby. By the end of this set of two articles, we'll be able to write things like
puts (even_numbers | tripler | incrementer | multiple_of_five ).resume and a palindrome finder using blocks:
This file contains hidden or 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
``` | |
debugger.rb:21 | |
a | |
(rdb:1) s | |
debugger.rb:4 | |
b | |
(rdb:1) | |
debugger.rb:8 | |
c | |
(rdb:1) |