pry-docmore 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pry-docmore.rb +63 -0
- data/pry-docmore.wiki/Home.md +96 -0
- data/pry-docmore.wiki/Ruby Global $! (DollarBang).md +15 -0
- data/pry-docmore.wiki/Ruby Global $/" (DollarQuote).md" +4 -0
- data/pry-docmore.wiki/Ruby Global $$ (DollarDollar).md +12 -0
- data/pry-docmore.wiki/Ruby Global $& (DollarAmpersand).md +16 -0
- data/pry-docmore.wiki/Ruby Global $' (DollarTick).md +16 -0
- data/pry-docmore.wiki/Ruby Global $* (DollarStar).md +1 -0
- data/pry-docmore.wiki/Ruby Global $+ (DollarPlus).md +9 -0
- data/pry-docmore.wiki/Ruby Global $, (DollarComma).md +1 -0
- data/pry-docmore.wiki/Ruby Global $-0 (DollarDashZero).md +1 -0
- data/pry-docmore.wiki/Ruby Global $-F (DollarDashF).md +1 -0
- data/pry-docmore.wiki/Ruby Global $-I (DollarDashI).md +1 -0
- data/pry-docmore.wiki/Ruby Global $-K (DollarDashK).md +1 -0
- data/pry-docmore.wiki/Ruby Global $-W (DollarDashW).md +1 -0
- data/pry-docmore.wiki/Ruby Global $-a (DollarDasha).md +1 -0
- data/pry-docmore.wiki/Ruby Global $-d (DollarDashd).md +1 -0
- data/pry-docmore.wiki/Ruby Global $-i (DollarDashi).md +1 -0
- data/pry-docmore.wiki/Ruby Global $-l (DollarDashl).md +1 -0
- data/pry-docmore.wiki/Ruby Global $-p (DollarDashp).md +1 -0
- data/pry-docmore.wiki/Ruby Global $-v (DollarDashv).md +1 -0
- data/pry-docmore.wiki/Ruby Global $-w (DollarDashw).md +1 -0
- data/pry-docmore.wiki/Ruby Global $. (DollarDot).md +1 -0
- data/pry-docmore.wiki/Ruby Global $0 (DollarZero).md +1 -0
- data/pry-docmore.wiki/Ruby Global $1 (DollarOne).md +1 -0
- data/pry-docmore.wiki/Ruby Global $2 (DollarTwo).md +1 -0
- data/pry-docmore.wiki/Ruby Global $3 (DollarThree).md +1 -0
- data/pry-docmore.wiki/Ruby Global $4 (DollarFour).md +1 -0
- data/pry-docmore.wiki/Ruby Global $5 (DollarFive).md +1 -0
- data/pry-docmore.wiki/Ruby Global $6 (DollarSix).md +1 -0
- data/pry-docmore.wiki/Ruby Global $7 (DollarSeven).md +1 -0
- data/pry-docmore.wiki/Ruby Global $8 (DollarEight).md +1 -0
- data/pry-docmore.wiki/Ruby Global $9 (DollarNine).md +1 -0
- data/pry-docmore.wiki/Ruby Global $: (DollarColon).md +3 -0
- data/pry-docmore.wiki/Ruby Global $; (DollarSemicolon).md +1 -0
- data/pry-docmore.wiki/Ruby Global $< (DollarLessthan).md +1 -0
- data/pry-docmore.wiki/Ruby Global $= (DollarEquals).md +2 -0
- data/pry-docmore.wiki/Ruby Global $> (DollarGreaterthan).md +1 -0
- data/pry-docmore.wiki/Ruby Global $? (Dollar?).md +11 -0
- data/pry-docmore.wiki/Ruby Global $@ (DollarAt).md +2 -0
- data/pry-docmore.wiki/Ruby Global $DEBUG (DollarDEBUG).md +1 -0
- data/pry-docmore.wiki/Ruby Global $FILENAME (DollarFILENAME).md +1 -0
- data/pry-docmore.wiki/Ruby Global $KCODE (DollarKCODE).md +1 -0
- data/pry-docmore.wiki/Ruby Global $LOADED_FEATURES (DollarLOADEDUnderscoreFEATURES).md +1 -0
- data/pry-docmore.wiki/Ruby Global $LOAD_PATH (DollarLOADUnderscorePATH).md +1 -0
- data/pry-docmore.wiki/Ruby Global $PROGRAM_NAME (DollarPROGRAMUnderscoreNAME).md +1 -0
- data/pry-docmore.wiki/Ruby Global $SAFE (DollarSAFE).md +4 -0
- data/pry-docmore.wiki/Ruby Global $VERBOSE (DollarVERBOSE).md +1 -0
- data/pry-docmore.wiki/Ruby Global $// (DollarBackslash).md" +1 -0
- data/pry-docmore.wiki/Ruby Global $_ (DollarUnderscore).md +1 -0
- data/pry-docmore.wiki/Ruby Global $` (DollarBacktick).md +16 -0
- data/pry-docmore.wiki/Ruby Global $stderr (Dollarstderr).md +1 -0
- data/pry-docmore.wiki/Ruby Global $stdin (Dollarstdin).md +1 -0
- data/pry-docmore.wiki/Ruby Global $stdout (Dollarstdout).md +1 -0
- data/pry-docmore.wiki/Ruby Global $~ (DollarSquiggle).md +1 -0
- data/pry-docmore.wiki/Ruby Global $/342/201/204 (DollarSlash).md" +3 -0
- data/pry-docmore.wiki/Ruby Keyword: BEGIN.md +14 -0
- data/pry-docmore.wiki/Ruby Keyword: END.md +10 -0
- data/pry-docmore.wiki/Ruby Keyword: __ENCODING__.md +8 -0
- data/pry-docmore.wiki/Ruby Keyword: __FILE__.md +5 -0
- data/pry-docmore.wiki/Ruby Keyword: __LINE__.md +12 -0
- data/pry-docmore.wiki/Ruby Keyword: alias.md +35 -0
- data/pry-docmore.wiki/Ruby Keyword: and.md +23 -0
- data/pry-docmore.wiki/Ruby Keyword: begin.md +24 -0
- data/pry-docmore.wiki/Ruby Keyword: break.md +16 -0
- data/pry-docmore.wiki/Ruby Keyword: case.md +23 -0
- data/pry-docmore.wiki/Ruby Keyword: class.md +4 -0
- data/pry-docmore.wiki/Ruby Keyword: def.md +14 -0
- data/pry-docmore.wiki/Ruby Keyword: defined?.md +13 -0
- data/pry-docmore.wiki/Ruby Keyword: do.md +3 -0
- data/pry-docmore.wiki/Ruby Keyword: else.md +4 -0
- data/pry-docmore.wiki/Ruby Keyword: elsif.md +3 -0
- data/pry-docmore.wiki/Ruby Keyword: end.md +2 -0
- data/pry-docmore.wiki/Ruby Keyword: ensure.md +1 -0
- data/pry-docmore.wiki/Ruby Keyword: false.md +9 -0
- data/pry-docmore.wiki/Ruby Keyword: for.md +14 -0
- data/pry-docmore.wiki/Ruby Keyword: if.md +5 -0
- data/pry-docmore.wiki/Ruby Keyword: in.md +3 -0
- data/pry-docmore.wiki/Ruby Keyword: module.md +3 -0
- data/pry-docmore.wiki/Ruby Keyword: next.md +15 -0
- data/pry-docmore.wiki/Ruby Keyword: nil.md +3 -0
- data/pry-docmore.wiki/Ruby Keyword: not.md +10 -0
- data/pry-docmore.wiki/Ruby Keyword: or.md +18 -0
- data/pry-docmore.wiki/Ruby Keyword: redo.md +16 -0
- data/pry-docmore.wiki/Ruby Keyword: rescue.md +55 -0
- data/pry-docmore.wiki/Ruby Keyword: retry.md +20 -0
- data/pry-docmore.wiki/Ruby Keyword: return.md +38 -0
- data/pry-docmore.wiki/Ruby Keyword: self.md +15 -0
- data/pry-docmore.wiki/Ruby Keyword: super.md +34 -0
- data/pry-docmore.wiki/Ruby Keyword: then.md +17 -0
- data/pry-docmore.wiki/Ruby Keyword: true.md +7 -0
- data/pry-docmore.wiki/Ruby Keyword: undef.md +5 -0
- data/pry-docmore.wiki/Ruby Keyword: unless.md +4 -0
- data/pry-docmore.wiki/Ruby Keyword: until.md +6 -0
- data/pry-docmore.wiki/Ruby Keyword: when.md +1 -0
- data/pry-docmore.wiki/Ruby Keyword: while.md +6 -0
- data/pry-docmore.wiki/Ruby Keyword: yield.md +16 -0
- metadata +181 -0
data/lib/pry-docmore.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'pry'
|
3
|
+
class Pry
|
4
|
+
class Docmore
|
5
|
+
def self.find_docs pattern
|
6
|
+
path = File.dirname(__FILE__) + '/../pry-docmore.wiki/*.md'
|
7
|
+
input = Dir[path].map do |file_name|
|
8
|
+
if file_name.match pattern
|
9
|
+
item = $1
|
10
|
+
item.sub! '⁄', '/' # Had to use Unicode "Fraction Slash" in filename.
|
11
|
+
[ item, File.read(file_name) ]
|
12
|
+
end
|
13
|
+
end.compact
|
14
|
+
Hash[input]
|
15
|
+
end
|
16
|
+
@DOCS = {
|
17
|
+
'Keyword' => {
|
18
|
+
source: 'ruby source, lex.c, circa line 219',
|
19
|
+
explanations: find_docs(%r/Ruby Keyword: (.+)\.md/)
|
20
|
+
},
|
21
|
+
'Global Variable' => {
|
22
|
+
source: 'Started from: http://www.zenspider.com/Languages/Ruby/QuickRef.html#pre-defined-variables',
|
23
|
+
explanations: find_docs(%r/Ruby Global (\S+)/)
|
24
|
+
},
|
25
|
+
}
|
26
|
+
def self.raw; @DOCS end
|
27
|
+
def self.explain thing
|
28
|
+
@DOCS.each do |label, docs|
|
29
|
+
# TODO: colored label
|
30
|
+
return docs[:explanations][thing] if docs[:explanations].has_key? thing
|
31
|
+
end
|
32
|
+
nil
|
33
|
+
end
|
34
|
+
|
35
|
+
ORIGINAL_SHOW_DOC ||= Pry.commands['show-doc']
|
36
|
+
Pry::Commands.create_command 'show-doc' do
|
37
|
+
description 'Show the documentation for a method/class/keyword/global. Aliases: ?'
|
38
|
+
command_options \
|
39
|
+
:shellwords => false,
|
40
|
+
:keep_retval => false
|
41
|
+
def process arg_string
|
42
|
+
if docmore = Pry::Docmore.explain(arg_string)
|
43
|
+
_pry_.output.puts docmore
|
44
|
+
$/
|
45
|
+
else
|
46
|
+
ORIGINAL_SHOW_DOC.new(context).call_safely(arg_string)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
Pry::Commands.create_command 'show-docmores' do
|
51
|
+
description 'List keywords and vars covered by pry-docmore'
|
52
|
+
def process
|
53
|
+
Pry::Docmore.raw.each do |label, docs|
|
54
|
+
# Pry needs a general mechanism to columnize things, and when it gets
|
55
|
+
# one, this can use it:
|
56
|
+
_pry_.output.puts "#{label}s".yellow + ': ' +
|
57
|
+
docs[:explanations].keys.join(' ')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
This is the input for the actual gem. Edit these, and the next time the gem
|
2
|
+
pushes, this info goes with it.
|
3
|
+
|
4
|
+
The goal is for this to be an informative set of docs, full of anything you can
|
5
|
+
think to add, so don't hold back.
|
6
|
+
|
7
|
+
- [Ruby Global $1 (DollarOne)](wiki/Ruby Global $1 (DollarOne\)) | [Ruby Global $2
|
8
|
+
(DollarTwo)](wiki/Ruby Global $2 (DollarTwo\)) | [Ruby Global $3 (DollarThree)](wiki/Ruby Global $3 (DollarThree\)) | [Ruby Global $4 (DollarFour)](wiki/Ruby Global $4 (DollarFour\)) | [Ruby Global $5 (DollarFive)](wiki/Ruby Global $5 (DollarFive\)) | [Ruby Global $6 (DollarSix)](wiki/Ruby Global $6 (DollarSix\)) | [Ruby Global $7 (DollarSeven)](wiki/Ruby Global $7 (DollarSeven\)) | [Ruby Global $8 (DollarEight)](wiki/Ruby Global $8 (DollarEight\)) | [Ruby Global $9 (DollarNine)](wiki/Ruby Global $9 (DollarNine\))
|
9
|
+
- [Ruby Global $& (DollarAmpersand)](wiki/Ruby Global $& (DollarAmpersand\))
|
10
|
+
- [Ruby Global $@ (DollarAt)](wiki/Ruby Global $@ (DollarAt\))
|
11
|
+
- [Ruby Global $` (DollarBacktick)](wiki/Ruby Global $` (DollarBacktick\))
|
12
|
+
- [Ruby Global $! (DollarBang)](wiki/Ruby Global $! (DollarBang\))
|
13
|
+
- [Ruby Global $= (DollarEquals)](wiki/Ruby Global $= (DollarEquals\))
|
14
|
+
- [Ruby Global $+ (DollarPlus)](wiki/Ruby Global $+ (DollarPlus\))
|
15
|
+
- [Ruby Global $⁄ (DollarSlash)](wiki/Ruby Global $⁄ (DollarSlash\))
|
16
|
+
- [Ruby Global $~ (DollarSquiggle)](wiki/Ruby Global $~ (DollarSquiggle\))
|
17
|
+
- [Ruby Global $' (DollarTick)](wiki/Ruby Global $' (DollarTick\))
|
18
|
+
- [Ruby Global $KCODE (DollarKCODE)](wiki/Ruby Global $KCODE (DollarKCODE\))
|
19
|
+
- [Ruby Global $-K (DollarDashK)](wiki/Ruby Global $-K (DollarDashK\))
|
20
|
+
- [Ruby Global $LOADED\_FEATURES (DollarLOADEDUnderscoreFEATURES)](wiki/Ruby Global $LOADED\_FEATURES (DollarLOADEDUnderscoreFEATURES\))
|
21
|
+
- [Ruby Global $PROGRAM\_NAME (DollarPROGRAMUnderscoreNAME)](wiki/Ruby Global $PROGRAM\_NAME (DollarPROGRAMUnderscoreNAME\))
|
22
|
+
- [Ruby Global $-W (DollarDashW)](wiki/Ruby Global $-W (DollarDashW\))
|
23
|
+
- [Ruby Global $\" (DollarQuote)](wiki/Ruby Global $\" (DollarQuote\))
|
24
|
+
- [Ruby Global $$ (DollarDollar)](wiki/Ruby Global $$ (DollarDollar\))
|
25
|
+
- [Ruby Global $* (DollarStar)](wiki/Ruby Global $* (DollarStar\))
|
26
|
+
- [Ruby Global $, (DollarComma)](wiki/Ruby Global $, (DollarComma\))
|
27
|
+
- [Ruby Global $-0 (DollarDashZero)](wiki/Ruby Global $-0 (DollarDashZero\))
|
28
|
+
- [Ruby Global $-F (DollarDashF)](wiki/Ruby Global $-F (DollarDashF\))
|
29
|
+
- [Ruby Global $-I (DollarDashI)](wiki/Ruby Global $-I (DollarDashI\))
|
30
|
+
- [Ruby Global $-a (DollarDasha)](wiki/Ruby Global $-a (DollarDasha\))
|
31
|
+
- [Ruby Global $-d (DollarDashd)](wiki/Ruby Global $-d (DollarDashd\))
|
32
|
+
- [Ruby Global $-i (DollarDashi)](wiki/Ruby Global $-i (DollarDashi\))
|
33
|
+
- [Ruby Global $-l (DollarDashl)](wiki/Ruby Global $-l (DollarDashl\))
|
34
|
+
- [Ruby Global $-p (DollarDashp)](wiki/Ruby Global $-p (DollarDashp\))
|
35
|
+
- [Ruby Global $-v (DollarDashv)](wiki/Ruby Global $-v (DollarDashv\))
|
36
|
+
- [Ruby Global $-w (DollarDashw)](wiki/Ruby Global $-w (DollarDashw\))
|
37
|
+
- [Ruby Global $. (DollarDot)](wiki/Ruby Global $. (DollarDot\))
|
38
|
+
- [Ruby Global $0 (DollarZero)](wiki/Ruby Global $0 (DollarZero\))
|
39
|
+
- [Ruby Global $: (DollarColon)](wiki/Ruby Global $: (DollarColon\))
|
40
|
+
- [Ruby Global $; (DollarSemicolon)](wiki/Ruby Global $; (DollarSemicolon\))
|
41
|
+
- [Ruby Global $< (DollarLessthan)](wiki/Ruby Global $< (DollarLessthan\))
|
42
|
+
- [Ruby Global $> (DollarGreaterthan)](wiki/Ruby Global $> (DollarGreaterthan\))
|
43
|
+
- [Ruby Global $? (Dollar?)](wiki/Ruby Global $? (Dollar?\))
|
44
|
+
- [Ruby Global $DEBUG (DollarDEBUG)](wiki/Ruby Global $DEBUG (DollarDEBUG\))
|
45
|
+
- [Ruby Global $FILENAME (DollarFILENAME)](wiki/Ruby Global $FILENAME (DollarFILENAME\))
|
46
|
+
- [Ruby Global $LOAD_PATH (DollarLOADUnderscorePATH)](wiki/Ruby Global $LOAD_PATH (DollarLOADUnderscorePATH\))
|
47
|
+
- [Ruby Global $VERBOSE (DollarVERBOSE)](wiki/Ruby Global $VERBOSE (DollarVERBOSE\))
|
48
|
+
- [Ruby Global $\\ (DollarBackslash)](wiki/Ruby Global $\\ (DollarBackslash\))
|
49
|
+
- [Ruby Global $_ (DollarUnderscore)](wiki/Ruby Global $_ (DollarUnderscore\))
|
50
|
+
- [Ruby Global $stderr (Dollarstderr)](wiki/Ruby Global $stderr (Dollarstderr\))
|
51
|
+
- [Ruby Global $stdin (Dollarstdin)](wiki/Ruby Global $stdin (Dollarstdin\))
|
52
|
+
- [Ruby Global $stdout (Dollarstdout)](wiki/Ruby Global $stdout (Dollarstdout\))
|
53
|
+
|
54
|
+
…
|
55
|
+
|
56
|
+
- [Ruby Keyword: alias](wiki/Ruby Keyword%3A alias)
|
57
|
+
- [Ruby Keyword: and](wiki/Ruby Keyword%3A and)
|
58
|
+
- [Ruby Keyword: begin](wiki/Ruby Keyword%3A begin)
|
59
|
+
- [Ruby Keyword: BEGIN](wiki/Ruby Keyword%3A BEGIN)
|
60
|
+
- [Ruby Keyword: break](wiki/Ruby Keyword%3A break)
|
61
|
+
- [Ruby Keyword: case](wiki/Ruby Keyword%3A case)
|
62
|
+
- [Ruby Keyword: class](wiki/Ruby Keyword%3A class)
|
63
|
+
- [Ruby Keyword: defined?](wiki/Ruby Keyword%3A defined?)
|
64
|
+
- [Ruby Keyword: def](wiki/Ruby Keyword%3A def)
|
65
|
+
- [Ruby Keyword: do](wiki/Ruby Keyword%3A do)
|
66
|
+
- [Ruby Keyword: else](wiki/Ruby Keyword%3A else)
|
67
|
+
- [Ruby Keyword: elsif](wiki/Ruby Keyword%3A elsif)
|
68
|
+
- [Ruby Keyword: \_\_ENCODING\_\_](wiki/Ruby Keyword%3A \_\_ENCODING\_\_)
|
69
|
+
- [Ruby Keyword: end](wiki/Ruby Keyword%3A end)
|
70
|
+
- [Ruby Keyword: END](wiki/Ruby Keyword%3A END)
|
71
|
+
- [Ruby Keyword: ensure](wiki/Ruby Keyword%3A ensure)
|
72
|
+
- [Ruby Keyword: false](wiki/Ruby Keyword%3A false)
|
73
|
+
- [Ruby Keyword: \_\_FILE\_\_](wiki/Ruby Keyword%3A \_\_FILE\_\_)
|
74
|
+
- [Ruby Keyword: for](wiki/Ruby Keyword%3A for)
|
75
|
+
- [Ruby Keyword: if](wiki/Ruby Keyword%3A if)
|
76
|
+
- [Ruby Keyword: in](wiki/Ruby Keyword%3A in)
|
77
|
+
- [Ruby Keyword: \_\_LINE\_\_](wiki/Ruby Keyword%3A \_\_LINE\_\_)
|
78
|
+
- [Ruby Keyword: module](wiki/Ruby Keyword%3A module)
|
79
|
+
- [Ruby Keyword: next](wiki/Ruby Keyword%3A next)
|
80
|
+
- [Ruby Keyword: nil](wiki/Ruby Keyword%3A nil)
|
81
|
+
- [Ruby Keyword: not](wiki/Ruby Keyword%3A not)
|
82
|
+
- [Ruby Keyword: or](wiki/Ruby Keyword%3A or)
|
83
|
+
- [Ruby Keyword: redo](wiki/Ruby Keyword%3A redo)
|
84
|
+
- [Ruby Keyword: rescue](wiki/Ruby Keyword%3A rescue)
|
85
|
+
- [Ruby Keyword: retry](wiki/Ruby Keyword%3A retry)
|
86
|
+
- [Ruby Keyword: return](wiki/Ruby Keyword%3A return)
|
87
|
+
- [Ruby Keyword: self](wiki/Ruby Keyword%3A self)
|
88
|
+
- [Ruby Keyword: super](wiki/Ruby Keyword%3A super)
|
89
|
+
- [Ruby Keyword: then](wiki/Ruby Keyword%3A then)
|
90
|
+
- [Ruby Keyword: true](wiki/Ruby Keyword%3A true)
|
91
|
+
- [Ruby Keyword: undef](wiki/Ruby Keyword%3A undef)
|
92
|
+
- [Ruby Keyword: unless](wiki/Ruby Keyword%3A unless)
|
93
|
+
- [Ruby Keyword: until](wiki/Ruby Keyword%3A until)
|
94
|
+
- [Ruby Keyword: when](wiki/Ruby Keyword%3A when)
|
95
|
+
- [Ruby Keyword: while](wiki/Ruby Keyword%3A while)
|
96
|
+
- [Ruby Keyword: yield](wiki/Ruby Keyword%3A yield)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
The $$ global is the process number of the Ruby running this script.
|
2
|
+
|
3
|
+
Can be used for process control tricks, such as recording in a "pidfile" so
|
4
|
+
other processes can later kill the current one, or accessing "/proc/#$$" on
|
5
|
+
systems (such as Linux) having a mounted procfs.
|
6
|
+
|
7
|
+
Traditionally used in shell scripts for a quick way to generate a semi-unique
|
8
|
+
temp filename, but this is better achieved like:
|
9
|
+
|
10
|
+
require 'tempfile'
|
11
|
+
t = Tempfile.new 'hi'
|
12
|
+
# produces a file like: /tmp/hi20121119-2774-1buu566 (because $$ == 2774)
|
@@ -0,0 +1 @@
|
|
1
|
+
The $* global is the ARGV, the command line arguments given for the script.
|
@@ -0,0 +1 @@
|
|
1
|
+
The $, global is the output field separator for the print and Array#join.
|
@@ -0,0 +1 @@
|
|
1
|
+
Aliased to $/
|
@@ -0,0 +1 @@
|
|
1
|
+
Aliased to $;
|
@@ -0,0 +1 @@
|
|
1
|
+
Aliased to $:
|
@@ -0,0 +1 @@
|
|
1
|
+
The $-K global ...pry-docmore TODO!
|
@@ -0,0 +1 @@
|
|
1
|
+
The $-W global ...pry-docmore TODO!
|
@@ -0,0 +1 @@
|
|
1
|
+
The $-a global True if option -a is set. Read-only variable.
|
@@ -0,0 +1 @@
|
|
1
|
+
Aliased to $DEBUG
|
@@ -0,0 +1 @@
|
|
1
|
+
The $-i global In in-place-edit mode, this variable holds the extension, otherwise nil.
|
@@ -0,0 +1 @@
|
|
1
|
+
The $-l global True if option -l is set. Read-only variable.
|
@@ -0,0 +1 @@
|
|
1
|
+
The $-p global True if option -p is set. Read-only variable.
|
@@ -0,0 +1 @@
|
|
1
|
+
Aliased to $VERBOSE
|
@@ -0,0 +1 @@
|
|
1
|
+
The $-w global True if option -w is set.
|
@@ -0,0 +1 @@
|
|
1
|
+
The $. global is the current input line number of the last file that was read.
|
@@ -0,0 +1 @@
|
|
1
|
+
The $0 global Same as $PROGRAM_NAME. Contains the name of the script being executed. May be assignable.
|
@@ -0,0 +1 @@
|
|
1
|
+
The $1 global is the 1st group of the last successful match. May be > 1.
|
@@ -0,0 +1 @@
|
|
1
|
+
The $2 global is the 2nd group of the last successful match. May be > 1.
|
@@ -0,0 +1 @@
|
|
1
|
+
The $3 global is the 3rd group of the last successful match. May be > 1.
|
@@ -0,0 +1 @@
|
|
1
|
+
The $4 global is the 4th group of the last successful match. May be > 1.
|
@@ -0,0 +1 @@
|
|
1
|
+
The $5 global is the 5th group of the last successful match. May be > 1.
|
@@ -0,0 +1 @@
|
|
1
|
+
The $6 global is the 6th group of the last successful match. May be > 1.
|
@@ -0,0 +1 @@
|
|
1
|
+
The $7 global is the 7th group of the last successful match. May be > 1.
|
@@ -0,0 +1 @@
|
|
1
|
+
The $8 global is the 8th group of the last successful match. May be > 1.
|
@@ -0,0 +1 @@
|
|
1
|
+
The $9 global is the 9th group of the last successful match. May be > 1.
|
@@ -0,0 +1 @@
|
|
1
|
+
The $; global is the separator for String#split (defaults to nil, which splits on whitespace).
|
@@ -0,0 +1 @@
|
|
1
|
+
The $< global is the virtual concatenation file of the files given on command line (or from $stdin if no files were given).
|
@@ -0,0 +1 @@
|
|
1
|
+
The $> global is the default output for print, printf. $stdout by default.
|
@@ -0,0 +1,11 @@
|
|
1
|
+
The $? global is the process status of the last executed child process.
|
2
|
+
|
3
|
+
It is of type Process::Status, which implements the following methods:
|
4
|
+
& == >> coredump? exited? exitstatus inspect pid signaled? stopped?
|
5
|
+
stopsig success? termsig to_i to
|
6
|
+
|
7
|
+
For example:
|
8
|
+
|
9
|
+
`head /dev/urandom | grep "Alas, poor Yorick! I knew him, Horatio…"`
|
10
|
+
$?.success?
|
11
|
+
# *probably* false
|
@@ -0,0 +1 @@
|
|
1
|
+
The $DEBUG global is the status of the -d switch.
|
@@ -0,0 +1 @@
|
|
1
|
+
The $FILENAME global Current input file from $<. Same as $<.filename.
|
@@ -0,0 +1 @@
|
|
1
|
+
The $KCODE global ...pry-docmore TODO!
|
@@ -0,0 +1 @@
|
|
1
|
+
The $LOADED_FEATURES global ...pry-docmore TODO!
|
@@ -0,0 +1 @@
|
|
1
|
+
Aliased to $:
|
@@ -0,0 +1 @@
|
|
1
|
+
The $PROGRAM_NAME global Same as $0 - Contains the name of the script being executed. May be assignable.
|
@@ -0,0 +1 @@
|
|
1
|
+
The $VERBOSE global is the verbose flag, which is set by the -v switch.
|
@@ -0,0 +1 @@
|
|
1
|
+
The $\ global is the output record separator for the print and IO#write. Default is nil.
|
@@ -0,0 +1 @@
|
|
1
|
+
The $_ global is the last input line of string by gets or readline.
|
@@ -0,0 +1 @@
|
|
1
|
+
The $stderr global is the current standard error output.
|
@@ -0,0 +1 @@
|
|
1
|
+
The $stdin global is the current standard input.
|
@@ -0,0 +1 @@
|
|
1
|
+
The $stdout global is the current standard output.
|
@@ -0,0 +1 @@
|
|
1
|
+
The $~ global is the match-data about the last match in the current scope.
|
@@ -0,0 +1,14 @@
|
|
1
|
+
Like Perl and Awk before that, defines a block to be run before the others:
|
2
|
+
|
3
|
+
p 3
|
4
|
+
BEGIN { p 1 }
|
5
|
+
p 4
|
6
|
+
BEGIN { p 2 }
|
7
|
+
# …prints these out as 1, 2, 3, 4
|
8
|
+
|
9
|
+
This works because the whole file gets parsed at the beginning (even though
|
10
|
+
'class' and 'def' lines are not executed early), so the interpreter can reorder
|
11
|
+
these statements.
|
12
|
+
|
13
|
+
See also: `END`
|
14
|
+
(Not to be confused with lower-case `begin`)
|
@@ -0,0 +1,8 @@
|
|
1
|
+
Read-only value of the current Encoding object (which has methods:
|
2
|
+
ascii_compatible? dummy? inspect name names replicate to_s)
|
3
|
+
|
4
|
+
By default is: #<Encoding:US-ASCII>
|
5
|
+
|
6
|
+
But can be affected by the 1st or 2nd line of the file being something like:
|
7
|
+
|
8
|
+
# encoding: utf-8
|
@@ -0,0 +1,12 @@
|
|
1
|
+
The code's current line number. Can be a handy way to pepper what would
|
2
|
+
otherwise be `print "Got here 1"` statements in your code, e.g.:
|
3
|
+
|
4
|
+
if a
|
5
|
+
p __LINE__
|
6
|
+
# some stuff
|
7
|
+
else
|
8
|
+
p __LINE__
|
9
|
+
# some other stuff
|
10
|
+
end
|
11
|
+
|
12
|
+
…but you use the pry-debugger gem instead, don't you?
|
@@ -0,0 +1,35 @@
|
|
1
|
+
The alias keyword is used to make synonyms of methods.
|
2
|
+
|
3
|
+
If you are used to the semantics of the `/bin/ln` command, get it out of your
|
4
|
+
head right now: Ruby does the opposite. That is, instead of `ln existing
|
5
|
+
new`, Ruby's semantics are `alias new existing`. (Mnested Mnemonic: this `new`
|
6
|
+
sorting is the b`a`-`n`-`e` of my `exist`ence.)
|
7
|
+
|
8
|
+
Also take particular note that this is not a method call, but a keyword, so
|
9
|
+
it can do things method calls cannot. The args are not :symbols (though they
|
10
|
+
are permitted to be), and it is a SyntaxError to attempt to place a comma
|
11
|
+
between the args.
|
12
|
+
|
13
|
+
Note that, this being a keyword and happening at compile-time, is not enough
|
14
|
+
to make dynamic assignments. See {Module#alias_method} for that kind of
|
15
|
+
trickery.
|
16
|
+
|
17
|
+
@example Basic Usage
|
18
|
+
def foo; 3 end
|
19
|
+
alias boo foo
|
20
|
+
boo
|
21
|
+
⇒ 3
|
22
|
+
@example Symbols as args
|
23
|
+
alias :zoo :boo # or even mix and match, if you want to for some reason.
|
24
|
+
zoo
|
25
|
+
⇒ 3
|
26
|
+
@example Some decorating!
|
27
|
+
alias orig_foo foo
|
28
|
+
def foo; 4 + orig_foo end
|
29
|
+
foo
|
30
|
+
⇒ 7
|
31
|
+
# See also Rails's alias_method_chain for a formalization of this idiom.
|
32
|
+
@param [unadorned symbol] New name
|
33
|
+
@param [unadorned symbol] Existing name
|
34
|
+
@return [NilClass] nil
|
35
|
+
@see http://kresimirbojcic.com/2011/12/01/decorators-in-ruby.html
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Boolean conjunction.
|
2
|
+
|
3
|
+
Only evaluates to `true` if both its left and right side are true.
|
4
|
+
|
5
|
+
Remember that the 'and' operator is lower precedence operator than '&&', so
|
6
|
+
|
7
|
+
an_expression and another_expression
|
8
|
+
is roughly equivalent to:
|
9
|
+
(an_expression) && (another_expression)
|
10
|
+
|
11
|
+
@example Truth table
|
12
|
+
true and true ⇒ true
|
13
|
+
false and true ⇒ false
|
14
|
+
false and false ⇒ false
|
15
|
+
@example Precedence
|
16
|
+
true and not false ⇒ true
|
17
|
+
true && not false ⇒ SyntaxError
|
18
|
+
a = true and false; a ⇒ true
|
19
|
+
a = true && false; a ⇒ false
|
20
|
+
@example The fowl chain
|
21
|
+
if false or true && false then false elsif true and false or true then true end
|
22
|
+
⇒ true
|
23
|
+
@see http://phrogz.net/ProgrammingRuby/language.html#table_18.4
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Opens a block when `def` or `do` isn't already opening one for you.
|
2
|
+
|
3
|
+
Uses include:
|
4
|
+
|
5
|
+
begin
|
6
|
+
1/0
|
7
|
+
rescue => e
|
8
|
+
p e
|
9
|
+
else
|
10
|
+
puts 'Cannot get here with that 1/0'
|
11
|
+
ensure
|
12
|
+
puts 'OK then.'
|
13
|
+
end
|
14
|
+
|
15
|
+
Or something like:
|
16
|
+
|
17
|
+
x = something_falsy || begin
|
18
|
+
several_steps
|
19
|
+
go_here
|
20
|
+
3
|
21
|
+
end
|
22
|
+
# Now x == 3
|
23
|
+
|
24
|
+
(Not to be confused with the BEGIN keyword.)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
A convenient conditional that doesn't require the "subject" to be repeated.
|
2
|
+
|
3
|
+
Uses #=== for comparison ("the threequals"), which is defined specially for
|
4
|
+
various objects.
|
5
|
+
|
6
|
+
x = 'asdf'
|
7
|
+
case x
|
8
|
+
when 'asdf'; puts 'Found it!'
|
9
|
+
when 'fghj'; puts 'Impossible.'
|
10
|
+
else puts 'Also impossible.'
|
11
|
+
end
|
12
|
+
|
13
|
+
case x
|
14
|
+
when String; puts 'Yep, will get here.'
|
15
|
+
when Array; puts 'Actually, wait a minute.'
|
16
|
+
when Hash; puts 'This is pretty bad OO.'
|
17
|
+
else puts 'But, the code works'
|
18
|
+
end
|
19
|
+
|
20
|
+
case x
|
21
|
+
when /^[fdsa]{4}/; puts 'Whoa, works with regexes.'
|
22
|
+
else puts 'Will not get here.'
|
23
|
+
end
|