pry-globs 0.1.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 662c6ef41067e82d995cd4cdc7a3efe1bbaba96d
4
- data.tar.gz: 228269a71f9199c3fad33198ef3476675c76bfa8
3
+ metadata.gz: 22a74ae52ed2d388992bb18a442e5d698ac67983
4
+ data.tar.gz: 95f022edb51f0c92b110b6f171daa5485a031ba4
5
5
  SHA512:
6
- metadata.gz: b76d6564450566406ec230e7c0924bce792bc2e3e9bdbbe37c53e6281a2db5a4d8c5e2942508b79f95ed0a45b6d97c267e1daa470ea8158f6694686dc1264e1d
7
- data.tar.gz: 3d305b31172f61abc2fd5a582fd8e021ac80562cfdafa0da9f320977a8aec4e0a2d1af511aa7b35c892ebe4b2b55539c2438d97e4eae716f4230fb4071ed9dbf
6
+ metadata.gz: f34dce36e6f25e10702240c66f433780f8cc077d2eb359e1689e9ff307373f956e129a55b4fd7dcbd54799e9776b7d26392eafde8dd7cb8f4c7edc8ba3c3ccc9
7
+ data.tar.gz: ce040bed976432442712ba5db9ef0895977f1f95561c27be44484f30b3932a0195d0369703e39da0d9658608883ddcf1780f4267bca48033c99b6fc91409599b
@@ -1,13 +1,17 @@
1
+ # Stdlib
2
+ require 'yaml'
3
+
4
+ # pry-globs
5
+ require_relative 'pry-globs/cli_arg'
6
+ require_relative 'pry-globs/cli_arg_validator'
7
+ require_relative 'pry-globs/ruby_identifier'
8
+ require_relative 'pry-globs/identifier_table'
1
9
  require_relative 'pry-globs/globs'
2
10
 
3
- Pry::Commands.create_command "globs" do
4
- description "Global variables, documented."
11
+ Pry::Commands.create_command 'globs' do
12
+ description 'Search for a description of Ruby\'s constants and global variables.'
5
13
 
6
14
  def process
7
- if args.size > 1
8
- raise Pry::CommandError, "You can pass only one global variable identifier."
9
- end
10
-
11
- output.puts Globs.find(args.first)
15
+ output.puts Globs.new(args).identifier_description
12
16
  end
13
17
  end
@@ -0,0 +1,51 @@
1
+ class CLIArg
2
+ attr_reader :options, :identifiers
3
+ attr_accessor :validator
4
+
5
+ def initialize(args)
6
+ @args = args
7
+ @options = fetch_options
8
+ @identifiers = fetch_identifiers
9
+ @validator = CLIArgValidator.new(self)
10
+ end
11
+
12
+ def invalid_msg
13
+ validator.args_invalid_msg
14
+ end
15
+
16
+ def invalid?
17
+ validator.args_invalid?
18
+ end
19
+
20
+ def valid
21
+ @valid ||= { option: option, identifier_token: identifier }
22
+ end
23
+
24
+ def option_present?
25
+ !valid[:option].empty?
26
+ end
27
+
28
+ def empty?
29
+ args.empty?
30
+ end
31
+
32
+ private
33
+
34
+ attr_reader :args
35
+
36
+ def fetch_options
37
+ args.select { |arg| arg[0] == '-' }
38
+ end
39
+
40
+ def fetch_identifiers
41
+ args.select { |arg| arg[0] != '-' }
42
+ end
43
+
44
+ def option
45
+ options.first || ''
46
+ end
47
+
48
+ def identifier
49
+ identifiers.first
50
+ end
51
+ end
@@ -0,0 +1,74 @@
1
+ class CLIArgValidator
2
+ CONSTANT_TOKENS = ('A'..'Z').to_a << '_'
3
+ ERROR_MESSAGES = {
4
+ 'invalid_options' => 'Only one option is supported: \'-e (explanation)\'.',
5
+ 'invalid_identifier_count' => "Globs accepts only one argument: e.g. '$!'.",
6
+ 'invalid_identifier_token' =>
7
+ 'Invalid Ruby identifier. It has to be valid global variable ("$0") or a valid constant token. ("RUBY_VERSION")',
8
+ 'invalid_argument_presence' => 'You have to pass at least one argument and it has to be an identifier.'
9
+ }.freeze
10
+
11
+ attr_reader :cli_args
12
+
13
+ def initialize(cli_args)
14
+ @cli_args = cli_args
15
+ end
16
+
17
+ def args_invalid?
18
+ invalid_argument_presence? || invalid_options? || identifiers_invalid?
19
+ end
20
+
21
+ def args_invalid_msg
22
+ method_names = %w(options identifier_count identifier_token argument_presence)
23
+ method_names.each_with_object([]) do |method, memo|
24
+ method = "invalid_#{method}"
25
+ memo << ERROR_MESSAGES[method] if send("#{method}?")
26
+ end.join("\n\n")
27
+ end
28
+
29
+ private
30
+
31
+ def invalid_options?
32
+ cli_args.options.size > 1 || incorrect_option?
33
+ end
34
+
35
+ def incorrect_option?
36
+ option_present? && cli_args.options.first != '-e'
37
+ end
38
+
39
+ def option_present?
40
+ !cli_args.options.empty?
41
+ end
42
+
43
+ def identifiers_invalid?
44
+ invalid_identifier_count? || malformed_identifier?
45
+ end
46
+
47
+ def invalid_identifier_count?
48
+ cli_args.identifiers.size != 1
49
+ end
50
+
51
+ def invalid_identifier_token?
52
+ !invalid_identifier_count? && malformed_identifier?
53
+ end
54
+
55
+ def malformed_identifier?
56
+ !(valid_global_variable? || valid_ruby_constant?)
57
+ end
58
+
59
+ def cli_args_identifier
60
+ @cli_args_identifier ||= cli_args.identifiers.first
61
+ end
62
+
63
+ def valid_global_variable?
64
+ cli_args_identifier[0] == '$'
65
+ end
66
+
67
+ def valid_ruby_constant?
68
+ cli_args_identifier.split(//).all? { |letter| CONSTANT_TOKENS.include? letter }
69
+ end
70
+
71
+ def invalid_argument_presence?
72
+ cli_args.empty?
73
+ end
74
+ end
@@ -1,19 +1,26 @@
1
+ # Stdlib
1
2
  require 'yaml'
2
3
 
3
- class Globs
4
- class << self
4
+ # pry-globs
5
+ require_relative 'cli_arg'
6
+ require_relative 'cli_arg_validator'
7
+ require_relative 'ruby_identifier'
8
+ require_relative 'identifier_table'
9
+ require_relative 'globs'
5
10
 
6
- def find(global_var)
7
- ruby_globals = load_yaml
11
+ class Globs
12
+ attr_reader :cli_args
13
+ attr_accessor :ruby_identifier
8
14
 
9
- return "Unexisting identifier." unless ruby_globals.key?(global_var)
15
+ def initialize(args)
16
+ @cli_args = CLIArg.new(args)
17
+ @ruby_identifier = RubyIdentifier.new(cli_args, IdentifierTable.new)
18
+ end
10
19
 
11
- ruby_globals.fetch(global_var)
12
- end
20
+ def identifier_description
21
+ return cli_args.invalid_msg if cli_args.invalid?
22
+ return ruby_identifier.absent_msg if ruby_identifier.absent_from_table?
13
23
 
14
- def load_yaml
15
- global_variables_path = File.expand_path('../global_variables.yaml', __FILE__)
16
- @ruby_variables ||= YAML.load_file(global_variables_path)
17
- end
24
+ ruby_identifier.description
18
25
  end
19
26
  end
@@ -0,0 +1,17 @@
1
+ class IdentifierTable
2
+ attr_reader :data
3
+
4
+ def initialize
5
+ @data = load_identifier_table
6
+ end
7
+
8
+ private
9
+
10
+ def load_identifier_table
11
+ YAML.load_file(identifier_data_file_path)
12
+ end
13
+
14
+ def identifier_data_file_path
15
+ File.expand_path('../../support/identifier_data.yaml', __FILE__)
16
+ end
17
+ end
@@ -0,0 +1,42 @@
1
+ class RubyIdentifier
2
+ attr_reader :token_table, :cli_args
3
+
4
+ def initialize(cli_args, identifier_table)
5
+ @token_table = identifier_table
6
+ @cli_args = cli_args
7
+ end
8
+
9
+ def description
10
+ definition + explanation
11
+ end
12
+
13
+ def absent_from_table?
14
+ token_data.nil?
15
+ end
16
+
17
+ def absent_msg
18
+ absent_from_table? ? "There is no information about '#{token}'.\n\nPlease submit data and open a PR!\n" : ''
19
+ end
20
+
21
+ private
22
+
23
+ def token
24
+ cli_args.valid[:identifier_token]
25
+ end
26
+
27
+ def identifier_type
28
+ @identifier_type ||= (token[0] == '$' ? 'global_variables' : 'constants')
29
+ end
30
+
31
+ def definition
32
+ token_data['definition']
33
+ end
34
+
35
+ def token_data
36
+ @token_data ||= token_table.data[identifier_type][token]
37
+ end
38
+
39
+ def explanation
40
+ cli_args.option_present? ? "\n#{token_data['explanation']}" : ''
41
+ end
42
+ end
@@ -0,0 +1,688 @@
1
+ constants:
2
+ ARGV:
3
+ definition: |
4
+ Definition:
5
+ Command line arguments passed to a script.
6
+ Also, the alias to the '$*' global variable.
7
+ explanation: |
8
+ Explanation:
9
+ It is possible to pass arguments to a Ruby script from the command line.
10
+
11
+ Given the script 'foo.rb' with contents:
12
+ > p ARGV
13
+
14
+ When it is run with 'ruby foo.rb hi you there', it will give the output:
15
+ > ["hi", "you", "there"]
16
+ ARGF:
17
+ definition: |
18
+ Definition:
19
+ The virtual concatenation file of the files given on command line
20
+ (or from $stdin if no files were given).
21
+ Also, alias to the '$<' global variable.
22
+ explanation: |
23
+ Explanation:
24
+ Given there are two .txt files within a directory..
25
+ hello.txt
26
+ > Hello there
27
+
28
+ john_doe.txt
29
+ > John Doe!
30
+
31
+ ..and a Ruby script.
32
+ concatenated_files.rb
33
+ > p ARGF.read
34
+ > p ARGF.read
35
+
36
+ When the script gets called 'ruby concatenated_files.rb hello.txt john_doe.txt',
37
+ it will produce the following output:
38
+ > "Hello there\nJohn Doe!\n"
39
+ > nil
40
+
41
+ Note that once the contents of ARGF have been read, they are removed.
42
+
43
+ ARGF also includes Enumerable module, so it is possible to use its methods
44
+ for manipulating contents of files passed to the script.
45
+ DATA:
46
+ definition: |
47
+ Definition:
48
+ The file object of the script, pointing just after __END__.
49
+ explanation: |
50
+ Explanation:
51
+ Ruby puts all data after __END__ in the file object and assigns it
52
+ to a DATA constant. It is possible to fetch that data by sending a
53
+ #read message to that file object.
54
+
55
+ Given this simple script 'foo.rb':
56
+ > puts "Check this out.."
57
+ > p DATA
58
+ > __END__
59
+ > Ruby
60
+ > has
61
+ > tricks.
62
+
63
+ Output of running 'ruby foo.rb' will be:
64
+ > Check this out.
65
+ > "Ruby\nhas\ntricks."
66
+ ENV:
67
+ definition: |
68
+ Definition:
69
+ The hash which contains current environment variables.
70
+ explanation: |
71
+ Explanation:
72
+ When printed out it will display names and values of
73
+ current environment variables within the shell session.
74
+
75
+ > p ENV # { "PAGER" => less, "RUBY_VERSION" => "ruby-2.3.0", ... }
76
+ RUBY_VERSION:
77
+ definition: |
78
+ Definition:
79
+ The ruby version string (VERSION was deprecated).
80
+ explanation: |
81
+ Explanation:
82
+ Simply print out running version of Ruby.
83
+ Does not provide information on patch.
84
+
85
+ > p RUBY_VERSION # => "2.3.0"
86
+ RUBY_RELEASE_DATE:
87
+ definition: |
88
+ Definition:
89
+ The release date string.
90
+ explanation: |
91
+ Explanation:
92
+ Prints out date (Y-M-D) when this version of Ruby was released.
93
+
94
+ > p RUBY_RELEASE_DATE # => "2015-12-25"
95
+ RUBY_PLATFORM:
96
+ definition: |
97
+ Definition:
98
+ The platform identifier.
99
+ explanation: |
100
+ Explanation:
101
+ > p RUBY_PLATFORM # "x86_64-darwin16"
102
+ global_variables:
103
+ $!:
104
+ definition: |
105
+ Definition:
106
+ The exception information message set by 'raise'.
107
+ explanation: |
108
+ Explanation:
109
+ It contains the exception when it is raised but not yet handled.
110
+ In most cases it can be accessed within the 'rescue' clause.
111
+
112
+ Given the following code..
113
+ > begin
114
+ > 5 / 0
115
+ > rescue
116
+ > p $! # => #<ZeroDivisionError: divided by 0>
117
+ > end
118
+
119
+ Or when raising exception manually..
120
+ > class MyError < StandardError
121
+ > end
122
+ >
123
+ > begin
124
+ > raise MyError, "Raise it high."
125
+ > rescue MyError
126
+ > p $! # => #<MyError: Raise it high.>
127
+ > p $!.message # => "Raise it high."
128
+ > end
129
+ $@:
130
+ definition: |
131
+ Definition:
132
+ Array of backtrace of the last exception thrown.
133
+ explanation: |
134
+ Explanation:
135
+ It will hold an array of strings that provide backtrace of the exception.
136
+
137
+ Given the following code..
138
+ > begin
139
+ > 5 / 0
140
+ > rescue
141
+ > p $@ # => ["example.rb:2 in `/'", "example.rb:2:in `<main>'"]
142
+ > end
143
+ $&:
144
+ definition: |
145
+ Definition:
146
+ The string matched by the last successful match.
147
+ explanation: |
148
+ Explanation:
149
+ It holds the string object of the last successful Regexp#match.
150
+ Essentially it stores matched text in contrast to MatchData object.
151
+
152
+ > oscar = "Oscar De La Hoya"
153
+ > regexp = /Oscar\s\D{5}/
154
+ > regexp.match(oscar)
155
+ > p $& # => "Oscar De La"
156
+ >
157
+ > oscar = "Oscar Wilde"
158
+ > regexp.match(oscar)
159
+ > p $& # => "Oscar Wilde"
160
+ > p $&.class # => String
161
+ $`:
162
+ definition: |
163
+ Definition:
164
+ The string to the left of the last successful match.
165
+ explanation: |
166
+ Explanation:
167
+ It stores the string left from the last successful Regexp#match.
168
+ String it stores is an "unsuccessful" match.
169
+
170
+ > /r/.match "Marlo"
171
+ > p $` # => "Ma"
172
+ "$'":
173
+ definition: |
174
+ Definition:
175
+ The string to the right of the last successful Regexp#match.
176
+ explanation: |
177
+ Explanation:
178
+ It stores the string right from the last successful match.
179
+ String it stores is an "unsuccessful" match.
180
+
181
+ > /r/.match "Marlo"
182
+ > p $"'" # => "lo"
183
+ $1:
184
+ definition: |
185
+ Definition:
186
+ The Nth group of the last successful match. May be > 1.
187
+ explanation: |
188
+ Explanation
189
+ When capturing is used within a regexp, captured results are assigned to
190
+ global variables by the order they are matched. Accordingly, '$1' would
191
+ contain first captured group, '$2' second one etc.
192
+
193
+ > day = "Such a nice day."
194
+ > result = /(S[uio].)h(\s[aeiou])/.match day
195
+ > p result # => MatchData "Such a" 1:"Suc" 2:" a">
196
+ > p result[1] # => "Suc"
197
+ > p result[2] # => " a"
198
+ > p $1 # => "Suc"
199
+ > p $2 # => " a"
200
+ $+:
201
+ definition: |
202
+ Definition:
203
+ Contains last capture group of the MatchData object.
204
+ explanation: |
205
+ Explanation:
206
+ It will contain the last group of all of them that are matched using
207
+ captures within a regexp.
208
+
209
+ > jd = "John Doe"
210
+ > rxp = /^([A-Z])...\s([A-Z])/
211
+ > match_data = rxp.match(jd)
212
+ > p $+ # => "D"
213
+
214
+ Last match can also be fetched this way:
215
+ > match_data[-1] # => "D"
216
+ $~:
217
+ definition: |
218
+ Definition:
219
+ The information about the last match in the current scope.
220
+ explanation: |
221
+ Explanation:
222
+ It holds a MatchData object created after a successful match.
223
+ Therefore, it is equal to the return value of Regexp::last_match.
224
+ More precise, it is the same object. This way, there is
225
+ no need to assign the result to a variable.
226
+
227
+ > rxp = /Joh[nN]/
228
+ > string = "Oh, hi JohN!"
229
+ > p $~ # => nil
230
+ > rxp =~ string
231
+ > p $~ # => #<MatchData "JohN">
232
+ > p Regexp.last_match # => #<MatchData "JohN">
233
+ > Regexp.last_match == $~ # => true
234
+ > Regexp.last_match.equal? $~ # => true
235
+ $=:
236
+ definition: |
237
+ Definition:
238
+ The flag for case insensitive, nil by default.
239
+ explanation: |
240
+ Explanation:
241
+ When referenced, Ruby states, "It is no longer effective".
242
+ $/:
243
+ definition: |
244
+ Definition:
245
+ The flag for case insensitive, nil by default.
246
+ explanation: |
247
+ Explanation:
248
+ In newer versions of Ruby, it states - "It is no longer effective".
249
+ $\:
250
+ definition: |
251
+ Definition:
252
+ The output record separator for the print and IO#write. Default is nil.
253
+ explanation: |
254
+ Explanation:
255
+ Value assigned to it, is appended to the end of the output when values are
256
+ passed to IO#print or when IO.write is called.
257
+
258
+ > $\ = "Nas"
259
+ > print "Name one cool guy -> " # => Name one cool guy -> Nas
260
+ $,:
261
+ definition: |
262
+ Definition:
263
+ The output field separator for the IO#print and Array#join.
264
+ explanation: |
265
+ Explanation:
266
+ If it is set, it will be used as a separator for joining arguments in
267
+ IO#print or Array#join.
268
+
269
+ > a = [1, 2, 3]
270
+ > a.join # => "123"
271
+ > $, = "<>"
272
+ > a.join # => "1<>2<>3"
273
+ > print 10, 20, 30 # => "10<>20<>30"
274
+ $;:
275
+ definition: |
276
+ Definition:
277
+ The default separator for String#split.
278
+ explanation: |
279
+ Explanation:
280
+ When set, String#split will split the string on the value assigned to it.
281
+
282
+ > s = "Have- to- do- it."
283
+ > s.split # => ["Have-", "to-", "do-", "it."]
284
+ > $; = '-'
285
+ > s.split # => ["Have", " to", " do", "it."]
286
+ $.:
287
+ definition: |
288
+ Definition:
289
+ The current input line number of the last file that was read.
290
+ explanation: |
291
+ Explanation:
292
+ There is no explanation for this cryptic global variable.
293
+ Please contribute and create a PR. Thank you.
294
+ $<:
295
+ definition: |
296
+ Definition:
297
+ The virtual concatenation file of the files given on command line
298
+ (or from $stdin if no files were given). Aliased by constant ARGF.
299
+ explanation: |
300
+ Explanation:
301
+ The virtual concatenation file of the files given by command line
302
+ arguments, or stdin (in case no argument file supplied). $<.file
303
+ returns the current filename.
304
+
305
+ Given there are two .txt files within a directory..
306
+ hello.txt
307
+ > Hello there
308
+
309
+ john_doe.txt
310
+ > John Doe!
311
+
312
+ ..and a Ruby script.
313
+ concatenated_files.rb
314
+ > p $<.file
315
+ > p $<.read
316
+ > p $<.file
317
+ > p $<.read
318
+ > p $<.file
319
+
320
+ Executing the script like so 'ruby concatenated_files.rb hello.txt john_doe.txt',
321
+ will produce the following output:
322
+ > #<File:hello.txt>
323
+ > "Hello there\nJohn Doe!\n"
324
+ > #<File:john_doe.txt (closed)>
325
+ > nil
326
+ > #<File:john_doe.txt (closed)>
327
+ $>:
328
+ definition: |
329
+ Definition:
330
+ The default output for print, printf. $stdout by default.
331
+ explanation: |
332
+ Explanation:
333
+ Assigning new output stream to $> will cause print to output its
334
+ arguments to the new output stream.
335
+
336
+ Given there is hello.txt file in the current directory, running the
337
+ following code..
338
+
339
+ > print "Check this out...\n" # => "Check this out...\n" gets printed
340
+ > # out on the command line.
341
+ > file_hi = File.read("./hello.txt")
342
+ > $> = file_hi
343
+ > print "Hi there You!\n"
344
+ > f.close
345
+
346
+ ..will put printed content to the given output stream.
347
+ In this case it will be a 'hello.txt' file. From the command line:
348
+ > cat hello.txt # Hi there You!
349
+ $_:
350
+ definition: |
351
+ Definition:
352
+ The last input line of string by gets or readline.
353
+ explanation: |
354
+ Explanation:
355
+ It gets assigned the last value read by gets or readline.
356
+
357
+ > word = gets # => Input from command line "Say 'Hi'."
358
+ > puts $_ # => "Say 'Hi'."
359
+ $0:
360
+ definition: |
361
+ Definition:
362
+ Contains the name of the script being executed. May be assignable.
363
+ explanation: |
364
+ Explanation:
365
+ If name of the current running Ruby script is "foobar.rb", then:
366
+
367
+ > p $0 # => "foobar.rb"
368
+ $*:
369
+ definition: |
370
+ Definition:
371
+ Command line arguments passed to a script.
372
+ Aliased to the ARGV constant.
373
+ explanation: |
374
+ Explanation:
375
+ It is possible to pass arguments to a Ruby script from the command line.
376
+
377
+ Given the script 'foo.rb' with contents:
378
+ > p $*
379
+
380
+ When it is run with 'ruby foo.rb hi you there', it will give the output:
381
+ > ["hi", "you", "there"]
382
+ $$:
383
+ definition: |
384
+ Definition:
385
+ Number of the process running the current script. The same identifier
386
+ is used by shells.
387
+ explanation: |
388
+ Explanation:
389
+ The $$ global variable will return the number of the current process. Simple.
390
+
391
+ > p $$ # => e.g. 8993
392
+ $?:
393
+ definition: |
394
+ Definition:
395
+ The status information on the last executed child process.
396
+ explanation: |
397
+ Explanation:
398
+ When a subprocess is terminated, its information is stored within
399
+ Process::Status object. Process.wait can be called to wait on termination
400
+ of any running child processes. In that case, information about the last
401
+ terminated child process is stored within $?.
402
+
403
+ Additional information:
404
+ If parent process terminates and it does not wait for child processes to
405
+ exit, those child processes that were still running at the time parent
406
+ process was terminated will be left running in the operating system.
407
+ They are known as "zombie processes".
408
+
409
+ Example session:
410
+ > # Firing up a child process
411
+ > Process.fork do
412
+ > puts "Code within the block gets executed within the child process."
413
+ > end
414
+ >
415
+ > # Do important stuff in the parent process
416
+ > 1 + 1
417
+ >
418
+ > # Wait for the termination of running child processes
419
+ > Process.wait
420
+ >
421
+ > # Upon termination of the child process store its information to $?
422
+ > $?.exitstatus # => e.g. 50501
423
+ > $?.success? # => true
424
+ > $?.stopped? # => false
425
+ $::
426
+ definition: |
427
+ Definition:
428
+ Load path for scripts and binary modules by load or require.
429
+ explanation: |
430
+ Explanation:
431
+ List of all directories Ruby searches for a file when Kernel#load and
432
+ Kernel#require are invoked.
433
+
434
+ > p $: # => ["/path/to/dir1", "/path/to/dir2", ...]
435
+ "$\"":
436
+ definition: |
437
+ Definition:
438
+ The array that includes file paths of all required files.
439
+ explanation: |
440
+ Explanation:
441
+ When requiring an existing file with Kernel#require for the first time,
442
+ the call will return 'true'. When requiring the same file again it will
443
+ return 'false'.
444
+ Based on the contents of the array assigned to '$""', Ruby can inspect
445
+ if it has already required a file. If it is present, the file does not
446
+ get required again.
447
+
448
+ Say the structure of the current working directory is:
449
+ - ./foo.rb
450
+ - ./bar/baz.rb
451
+ If we require 'baz.rb' from 'foo.rb', then '$"' would contain the path
452
+ of 'baz.rb' after we require it.
453
+
454
+ > # First we make sure to add the directory to Ruby's $LOAD_PATH so that
455
+ > # it can find the file.
456
+ > dir = File.expand_path("../bar", __FILE__)
457
+ > $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
458
+ >
459
+ > # $" still does not contain "/path/to/bar/baz.rb".
460
+ > # We just added the directory to the $LOAD_PATH.
461
+ > $".include? "path/to/bar/baz.rb" => false
462
+ >
463
+ > # Then we require the file.
464
+ > require 'baz' # => true
465
+ >
466
+ > # After we require it, the path to bar.rb is present in $\"
467
+ > $".include? "path/to/bar/baz.rb" => true
468
+ $-0:
469
+ definition: |
470
+ Definition:
471
+ Alias to the $/.
472
+
473
+ The flag for case insensitive, nil by default.
474
+ explanation: |
475
+ Explanation:
476
+ In newer versions of Ruby, it states - "It is no longer effective".
477
+ $-a:
478
+ definition: |
479
+ Definition:
480
+ True if option -a is set. Read-only variable.
481
+ explanation: |
482
+ Explanation:
483
+ It turns on auto-split mode when used with -n or -p. In auto-split mode,
484
+ Ruby executes '$F = $_.split' at beginning of each loop.
485
+ $-d:
486
+ definition: |
487
+ Definition:
488
+ It turns on both verbose and debugging mode.
489
+ explanation: |
490
+ Explanation:
491
+ Turns on both verbose and debugging mode.
492
+
493
+ I suppose you'd rather use Pry instead of debuggin your programs with
494
+ Ruby's options.
495
+ $-F:
496
+ definition: |
497
+ Definition:
498
+ Specify input field separator from the command line.
499
+
500
+ Alias to $;.
501
+ explanation: |
502
+ Explanation:
503
+ If -F is passed from the command line, its value will get assigned to $-F.
504
+
505
+ When $; gets assigned this way, it is a Regexp and not a string.
506
+
507
+ $: ruby -F"<" foo.rb
508
+ > p $; # => /</
509
+ > p "It<splits" # => ["It", "splits"]
510
+ $-i:
511
+ definition: |
512
+ Definition:
513
+ Specifies in-place-edit mode. The extension, if specified, is added to
514
+ old file name to make a backup copy.
515
+ explanation: |
516
+ Explanation:
517
+ If switch is provided, Ruby will take the contents of the provided file
518
+ argument and create new file with its contents.
519
+ New backup file will have the extension provided through the command line
520
+ along the option itself, such as '-i.bak'.
521
+
522
+ With the following files:
523
+ - og.txt
524
+ > original content
525
+ - script.rb
526
+ > gets
527
+ > File.open("./og.txt", "w+") { |file| file.puts "new content" }
528
+
529
+ When the script gets invoked like so: 'ruby -i.bak script.rb og.txt',
530
+ new file 'og.txt.bak' will get created with the content of the initial
531
+ 'og.txt file'.
532
+
533
+ > $: cat og.txt
534
+ > $: new content
535
+ > $: cat og.txt.bak
536
+ > $: original content
537
+ $-I:
538
+ definition: |
539
+ Definition:
540
+ Instructs Ruby on where to load the library scripts from. Directory path
541
+ will be added to the load-path variable ($:).
542
+ explanation: |
543
+ Explanation:
544
+ Providing this option on a command line will put listed directory in the
545
+ beginning of the list of directories where Ruby will search for library
546
+ files.
547
+
548
+ The following line places current directory on the $LOAD_PATH, meaning
549
+ it is possible to require files within from the script being executed.
550
+
551
+ > $: ruby -I $(pwd) foo.rb
552
+ $-l:
553
+ definition: |
554
+ Definition:
555
+ True if option -lis set. Read-only variable.
556
+ explanation: |
557
+ Explanation:
558
+ Enables automatic line-ending processing, which means to firstly set $\
559
+ to the value of $/, and secondly chops every line read using chop!.
560
+ $-p:
561
+ definition: |
562
+ Definition:
563
+ True if option -p is set. Read-only variable.
564
+ explanation: |
565
+ Explanation:
566
+ Acts mostly as -n switch, but print the value of the variable $_ at the
567
+ end of each loop.
568
+ $-v:
569
+ definition: |
570
+ Definition:
571
+ The alias to the $VERBOSE.
572
+ explanation: |
573
+ Explanation:
574
+ Enables verbose mode. Ruby will print its version at the beginning and
575
+ set the variable $VERBOSE to true. If this switch is given, and no other
576
+ switches are present, Ruby quits after printing its version.
577
+ $-w:
578
+ definition: |
579
+ Definition:
580
+ Enables verbose mode without printing version message at the beginning.
581
+ It set variable '$VERBOSE' to true.
582
+ explanation: |
583
+ Explanation:
584
+ Enables verbose mode. Ruby will NOT print its version at the beginning and
585
+ set the variable $VERBOSE to true. Some methods print extra messages if
586
+ this variable is true.
587
+ $stderr:
588
+ definition: |
589
+ Definition:
590
+ The current standard error output.
591
+ explanation: |
592
+ Explanation:
593
+ Content that will be outputted to standard error stream.
594
+
595
+ Ruby script:
596
+ > $stderr.puts "the content"
597
+
598
+ Command line session:
599
+ > $: ruby script.rb 2> stderr
600
+ > $: cat stderr
601
+ > $: the content
602
+ $stdin:
603
+ definition: |
604
+ Definition:
605
+ The current standard input.
606
+ explanation: |
607
+ Explanation:
608
+ Instance of IO class.
609
+ Example: takes input from a file passed through the command line.
610
+
611
+ Given the file 'hi.txt':
612
+ > Hi
613
+ > there.
614
+ And the script 'foo.rb':
615
+ > p $stdin.read
616
+ Running the script like so 'ruby foo.rb < hi.txt',
617
+ will produce the output:
618
+ "Hi\nthere.\n"
619
+ $stdout:
620
+ definition: |
621
+ Definition:
622
+ The current standard output.
623
+ explanation: |
624
+ Explanation:
625
+ Instance of IO class.
626
+ Example: uses a file as a standard output.
627
+
628
+ Given the script:
629
+ > f = File.open("hello.txt", "w+")
630
+ > $stdout = f
631
+ > $stdout.puts "Hi there!"
632
+ > f.close
633
+ Contents of the 'hello.txt' will be:
634
+ > $: cat hello.txt
635
+ > $: Hi there!
636
+ $LOADED_FEATURES:
637
+ definition: |
638
+ Definition:
639
+ List of all the features required in the current program.
640
+ explanation: |
641
+ Explanation:
642
+ Before Ruby starts the execution it loads a list of features/files.
643
+ It loads C extensions, as well as Ruby files.
644
+ $LOADED_FEATURES gives the list of file paths for each file Ruby
645
+ requires before it runs the given program.
646
+ It differs from $LOAD_PATH in that $LOAD_PATH is a list of all directories
647
+ Ruby searches for when a file is required, while $LOADED_FEATURES is a
648
+ list of actual features loaded.
649
+ $LOAD_PATH:
650
+ definition: |
651
+ Definition:
652
+ Load path for scripts and binary modules by load or require.
653
+
654
+ Alias for $:.
655
+ explanation: |
656
+ Explanation:
657
+ List of all directories Ruby searches for a file when Kernel#load and
658
+ Kernel#require are invoked.
659
+
660
+ > p $: # => ["/path/to/dir1", "/path/to/dir2", ...]
661
+ $VERBOSE:
662
+ definition: |
663
+ Definition:
664
+ Stores the verbose flag. Setting it to 'true' is the same as executing
665
+ a script with '-w' or '-v' option.
666
+ explanation: |
667
+ Explanation:
668
+ Setting it to 'true' will, for example, give a warning if there is a set
669
+ but unused variable within the program.
670
+
671
+ Given the script:
672
+ > p $VERBOSE
673
+ > string = "random"
674
+
675
+ When it is run with -w option, it will set $VERBOSE to 'true' and give
676
+ appropriate warning ('assigned but unused variable - a' in this case.)
677
+ When it is run without an option, it will simply print out 'false' for
678
+ $VERBOSE global variable.
679
+ $DEBUG:
680
+ definition: |
681
+ Definition:
682
+ The debug flag, which is set by the -d switch.
683
+ explanation: |
684
+ Explanation:
685
+ Enabling debug output prints each exception raised to $stderr (but not
686
+ its backtrace). Setting this to a true value enables debug output as if
687
+ -d were given on the command line. Setting this to a false value disables
688
+ debug output.
metadata CHANGED
@@ -1,30 +1,106 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry-globs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - dariodaic
7
+ - Dario Daic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-25 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2016-12-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: codeclimate-test-reporter
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
13
83
  description:
14
- email:
15
- - dariodaic5.1@gmail.com
84
+ email: dariodaic5.1@gmail.com
16
85
  executables: []
17
86
  extensions: []
18
87
  extra_rdoc_files: []
19
88
  files:
20
89
  - lib/pry-globs.rb
21
- - lib/pry-globs/global_variables.yaml
90
+ - lib/pry-globs/cli_arg.rb
91
+ - lib/pry-globs/cli_arg_validator.rb
22
92
  - lib/pry-globs/globs.rb
23
- homepage: https://github.com/dariodaic/pry-globs
93
+ - lib/pry-globs/identifier_table.rb
94
+ - lib/pry-globs/ruby_identifier.rb
95
+ - lib/support/identifier_data.yaml
96
+ homepage: https://github.com/da1chy/pry-globs
24
97
  licenses:
25
98
  - MIT
26
99
  metadata: {}
27
- post_install_message:
100
+ post_install_message: |-
101
+ Hidden meaning of Ruby's global variables and constants - revealed.
102
+
103
+ Thank you for installing pry-globs.
28
104
  rdoc_options: []
29
105
  require_paths:
30
106
  - lib
@@ -32,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
32
108
  requirements:
33
109
  - - ">="
34
110
  - !ruby/object:Gem::Version
35
- version: 2.2.0
111
+ version: 2.3.0p0
36
112
  required_rubygems_version: !ruby/object:Gem::Requirement
37
113
  requirements:
38
114
  - - ">="
@@ -43,6 +119,6 @@ rubyforge_project:
43
119
  rubygems_version: 2.5.1
44
120
  signing_key:
45
121
  specification_version: 4
46
- summary: Pry plugin for describing global variables.
122
+ summary: Decipher Ruby's notoriously cryptic global variables and constants within
123
+ a Pry session.
47
124
  test_files: []
48
- has_rdoc:
@@ -1,48 +0,0 @@
1
- --- # Ruby's global variables
2
- $!: The exception information message set by ‘raise’.
3
- $@: Array of backtrace of the last exception thrown.
4
- $&: The string matched by the last successful match.
5
- $`: The string to the left of the last successful match.
6
- #$"'": The string to the right of the last successful match.
7
- $+: The highest group matched by the last successful match.
8
- $1: The Nth group of the last successful match. May be > 1.
9
- $~: The information about the last match in the current scope.
10
- $=: The flag for case insensitive, nil by default.
11
- $/: The input record separator, newline by default.
12
- $\: The output record separator for the print and IO#write. Default is nil.
13
- $,: The output field separator for the print and Array#join.
14
- $;: The default separator for String#split.
15
- $.: The current input line number of the last file that was read.
16
- $<: The virtual concatenation file of the files given on command line (or from $stdin if no files were given).
17
- $>: The default output for print, printf. $stdout by default.
18
- $_: The last input line of string by gets or readline.
19
- $0: Contains the name of the script being executed. May be assignable.
20
- $*: Command line arguments given for the script sans args.
21
- $$: The process number of the Ruby running this script.
22
- $?: The status of the last executed child process. This value is thread-local.
23
- $:: Load path for scripts and binary modules by load or require.
24
- $\:: The array contains the module names loaded by require.
25
- $-o: The alias to $/
26
- $-a: True if option -a is set. Read-only variable.
27
- $-d: The alias of $DEBUG.
28
- $-F: The alias to $;.
29
- $-i: In in-place-edit mode, this variable hods the extension, otherwise nil.
30
- $-I: The alias to $:.
31
- $-l: True if option -l is set. Read-only varaible.
32
- $-p: True if option -p is set. Read-only variable.
33
- $-v: An alias of $VERBOSE.
34
- $-w: An alias of $VERBOSE.
35
- $LOADED_FEATURES: The alias to the $"'".
36
- $FILENAME: Current input file from $<. Same as $<.filename.
37
- $LOAD_PATH: The alias to the $:.
38
- $stderr: The current standard error output.
39
- $stding: The current standard input.
40
- $stdout: The current standard output.
41
- $ARGV: An alias of $*.
42
- $VERBOSE: The verbose flag, which is set by the -w or -v switch. Setting this to a true value enables warnings as if -w or -v were given on the command line. Setting this to nil disables warnings, including from Kernel#warn.
43
- $DEBUG: The debug flag, which is set by the -d switch. Enabling debug output prints each exception raised to $stderr.
44
- ENV: The hash contains current environment variables.
45
- ARGV: The alias to the $*.
46
- RUBY_VERSION: The ruby version string (VERSION was deprecated).
47
- RUBY_RELEASE_DATE: The release date string.
48
- RUBY_PLATFORM: The platform identifier.