Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed some README typos.

  • Loading branch information...
commit bd01f5237106d8c5059455002df7d99d805f5a81 1 parent ca827b7
Alex Fortuna authored

Showing 1 changed file with 134 additions and 134 deletions. Show diff stats Hide diff stats

  1. +134 134 README.md
268 README.md
Source Rendered
... ... @@ -1,134 +1,134 @@
1   -Yet another set of IRB hacks
2   -============================
3   -
4   -Setup
5   ------
6   -
7   - $ gem sources --add http://gemcutter.org
8   - $ gem install irb_hacks
9   -
10   -Add to your `~/.irbrc`:
11   -
12   - require "rubygems"
13   - require "irb_hacks"
14   -
15   -Now fire up IRB for a quick test:
16   -
17   - $ irb
18   - irb> ae
19   - (snippet)>>
20   -
21   -If you see "(snippet)", you're ready to go.
22   -
23   -
24   -The Hacks
25   ----------
26   -
27   -### Code snippets -- `a` and `ae` ###
28   -
29   -There's often a need to invoke our work-in-progress code a number of times using the same arguments, wrapping block, etc. For that, "code snippets" feature is quite handy.
30   -
31   -`irb_hacks` gem provides the two methods with short, meaningless (and thus conflict-free) names -- `a` and `ae`. `a` means nothing, it's just the first letter of the alphabet. `a` **invokes** the last-edited snippet. `ae` **lets you edit** the actual snippet (it roughly stands for "a" + "edit").
32   -
33   -A very basic example:
34   -
35   - irb> ae
36   - (snippet)>> puts "Hello, world"
37   - irb> a
38   - Hello, world
39   -
40   -Snippet arguments are supported. It's an array called `args` in snippet context.
41   -
42   - irb> ae
43   - (snippet)>> p "args", args
44   - irb> a 10, 1.0, "a string"
45   - "args"
46   - [10, 1.0, "a string"]
47   -
48   -Snippets work just like normal Ruby methods -- they return the value of the last statement executed.
49   -
50   - irb> ae
51   - (snippet)>> ["alfa", "zulu", "bravo"] + args
52   - irb> puts a("charlie").sort
53   - alfa
54   - bravo
55   - charlie
56   - zulu
57   -
58   -Snippets support code blocks. It's a `Proc` called `block` in snippet context. Usage example follows (suppose we're building a simplistic `/etc/passwd` parser).
59   -
60   - irb> ae
61   - (snippet)>> File.readlines("/etc/passwd").map(&block).each {|s| p s}; nil
62   - irb> a {|s| ar = s.split(":"); {:name => ar[0], :uid => ar[2]}}
63   - {:uid=>"0", :name=>"root"}
64   - {:uid=>"1", :name=>"bin"}
65   - {:uid=>"2", :name=>"daemon"}
66   - {:uid=>"3", :name=>"adm"}
67   - ...
68   -
69   -Snippets are **persistent** though IRB invocations. That's quite handy, since not all stuff can be dynamically reloaded and sometimes we have to restart IRB to ensure clean reload.
70   -
71   - irb> ae
72   - (snippet)>> puts "Snippets are persistent!"
73   - irb> exit
74   - $ irb
75   - irb> a
76   - Snippets are persistent!
77   -
78   -Just in case, snippet history file is called `.irb_snippet_history` in your `$HOME`.
79   -
80   -Snippets maintain **their own** Realine history. When you press [Up] and [Down] keys in `ae`, you browse the previously used snippets, not just your previous IRB input. Don't retype the snippet you used yesterday -- press [Up] a couple times and you'll see it.
81   -
82   - irb> ae
83   - (snippet)>> puts "snippet one"
84   - irb> hala
85   - irb> bala
86   - irb> ae
87   - (snippet)>> puts "snippet two"
88   - irb> foo
89   - irb> moo
90   - irb> ae
91   - (snippet)>>
92   - ## Pressing [Up] will give you...
93   - (snippet)>> puts "snippet two"
94   - ## Pressing [Up] again will give you...
95   - (snippet)>> puts "snippet one"
96   -
97   -### Browse program data with GNU `less` ###
98   -
99   -Sometimes the data your code works with is too long to fit in a console window. The clearest example of this are variables filled with text content, e.g. [Hpricot](http://github.com/whymirror/hpricot) documents/elements.
100   -
101   -To solve that, the greatest paging program of all times, GNU `less`, comes to the rescue.
102   -
103   - $ irb
104   - irb> files = Dir["/etc/*"].sort
105   - ## Some bulky array...
106   - irb> less files
107   - ## ... which we browse interactively :).
108   -
109   -In block form, `less` hack intercepts everything output to `STDOUT` (and, optionally, to `STDERR`), and feeds it to the pager.
110   -
111   - $ irb
112   - irb> less do
113   - puts "Hello, world"
114   - end
115   -
116   -Now with `STDERR` capture:
117   -
118   - $ irb
119   - irb> less(:stderr) do
120   - puts "to stdout"
121   - STDERR.puts "to stderr"
122   - end
123   -
124   -To specify another paging program or tweak `less` options, write in your `~/.irbrc`:
125   -
126   - IrbHacks.less_cmd = "more"
127   -
128   -, or something else you find appropriate.
129   -
130   -
131   -Feedback
132   ---------
133   -
134   -Send bug reports, suggestions and criticisms through [project's page on GitHub](http://github.com/dadooda/irb_hacks).
  1 +Yet another set of IRB hacks
  2 +============================
  3 +
  4 +Setup
  5 +-----
  6 +
  7 + $ gem sources --add http://gemcutter.org
  8 + $ gem install irb_hacks
  9 +
  10 +Add to your `~/.irbrc`:
  11 +
  12 + require "rubygems"
  13 + require "irb_hacks"
  14 +
  15 +Now fire up IRB for a quick test:
  16 +
  17 + $ irb
  18 + irb> ae
  19 + (snippet)>>
  20 +
  21 +If you see "(snippet)", you're ready to go.
  22 +
  23 +
  24 +The Hacks
  25 +---------
  26 +
  27 +### Code snippets -- `a` and `ae` ###
  28 +
  29 +There's often a need to invoke our work-in-progress code a number of times using the same arguments, wrapping block, etc. For that, "code snippets" feature is quite handy.
  30 +
  31 +`irb_hacks` gem provides the two methods with short, meaningless (and thus conflict-free) names -- `a` and `ae`. `a` means nothing, it's just the first letter of the alphabet. `a` **invokes** the last-edited snippet. `ae` **lets you edit** the actual snippet (it roughly stands for "a" + "edit").
  32 +
  33 +A very basic example:
  34 +
  35 + irb> ae
  36 + (snippet)>> puts "Hello, world"
  37 + irb> a
  38 + Hello, world
  39 +
  40 +Snippet arguments are supported. It's an array called `args` in snippet context.
  41 +
  42 + irb> ae
  43 + (snippet)>> p "args", args
  44 + irb> a 10, 1.0, "a string"
  45 + "args"
  46 + [10, 1.0, "a string"]
  47 +
  48 +Snippets work just like normal Ruby methods -- they return the value of the last statement executed.
  49 +
  50 + irb> ae
  51 + (snippet)>> ["alfa", "zulu", "bravo"] + args
  52 + irb> puts a("charlie").sort
  53 + alfa
  54 + bravo
  55 + charlie
  56 + zulu
  57 +
  58 +Snippets support code blocks. It's a `Proc` called `block` in snippet context. Usage example follows (suppose we're building a simplistic `/etc/passwd` parser).
  59 +
  60 + irb> ae
  61 + (snippet)>> File.readlines("/etc/passwd").map(&block).each {|s| p s}; nil
  62 + irb> a {|s| ar = s.split(":"); {:name => ar[0], :uid => ar[2]}}
  63 + {:uid=>"0", :name=>"root"}
  64 + {:uid=>"1", :name=>"bin"}
  65 + {:uid=>"2", :name=>"daemon"}
  66 + {:uid=>"3", :name=>"adm"}
  67 + ...
  68 +
  69 +Snippets are **persistent** though IRB invocations. That's quite handy, since not all stuff can be dynamically reloaded and sometimes we have to restart IRB to ensure a clean reload.
  70 +
  71 + irb> ae
  72 + (snippet)>> puts "Snippets are persistent!"
  73 + irb> exit
  74 + $ irb
  75 + irb> a
  76 + Snippets are persistent!
  77 +
  78 +Just in case, snippet history file is called `.irb_snippet_history` in your `$HOME`.
  79 +
  80 +Snippets maintain **their own** Readline history. When you press [Up] and [Down] keys in `ae`, you browse the previously used snippets, not just your previous IRB input. Don't retype the snippet you used yesterday -- press [Up] a couple times and you'll see it.
  81 +
  82 + irb> ae
  83 + (snippet)>> puts "snippet one"
  84 + irb> hala
  85 + irb> bala
  86 + irb> ae
  87 + (snippet)>> puts "snippet two"
  88 + irb> foo
  89 + irb> moo
  90 + irb> ae
  91 + (snippet)>>
  92 + ## Pressing [Up] will give you...
  93 + (snippet)>> puts "snippet two"
  94 + ## Pressing [Up] again will give you...
  95 + (snippet)>> puts "snippet one"
  96 +
  97 +### Browse program data with GNU `less` ###
  98 +
  99 +Sometimes the data your code works with is too long to fit in a console window. The clearest example of this are variables filled with text content, e.g. [Hpricot](http://github.com/whymirror/hpricot) documents/elements.
  100 +
  101 +To solve that, the greatest paging program of all times, GNU `less`, comes to the rescue.
  102 +
  103 + $ irb
  104 + irb> files = Dir["/etc/*"].sort
  105 + ## Some bulky array...
  106 + irb> less files
  107 + ## ... which we browse interactively :).
  108 +
  109 +In block form, `less` hack intercepts everything output to `STDOUT` (and, optionally, to `STDERR`), and feeds it to the pager.
  110 +
  111 + $ irb
  112 + irb> less do
  113 + puts "Hello, world"
  114 + end
  115 +
  116 +Now with `STDERR` capture:
  117 +
  118 + $ irb
  119 + irb> less(:stderr) do
  120 + puts "to stdout"
  121 + STDERR.puts "to stderr"
  122 + end
  123 +
  124 +To specify another paging program or tweak `less` options, write in your `~/.irbrc`:
  125 +
  126 + IrbHacks.less_cmd = "more"
  127 +
  128 +, or something else you find appropriate.
  129 +
  130 +
  131 +Feedback
  132 +--------
  133 +
  134 +Send bug reports, suggestions and criticisms through [project's page on GitHub](http://github.com/dadooda/irb_hacks).

0 comments on commit bd01f52

Please sign in to comment.
Something went wrong with that request. Please try again.