explore_rb 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +107 -0
- data/Rakefile +1 -0
- data/explore_rb.gemspec +20 -0
- data/lib/explore_rb/version.rb +3 -0
- data/lib/explore_rb.rb +57 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e789a5bea07085d3d886cdc7bad1ef239e077032
|
4
|
+
data.tar.gz: bbf83d6df5a2867654cb299f47227b2d60d8b0ad
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8be37b2381362b8a395cce21984c59b4143e92224931675035b1070f5762891f3f37f75650b8e8c76aa9e2712eb635839608e845ce3c4182fb970514533b2fdb
|
7
|
+
data.tar.gz: 59a5ab6e3fd7a7341896251186209b0b91c50c3300f0973a8d6620f6f13c03485ac1b7a41f0f3848d01c114c4bfbf3d710887607815a8c9daa358fcafc025707
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Mike Williamson
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
# ExploreRb
|
2
|
+
|
3
|
+
This is a gem that aims to add a little "discoverability" to IRB. It does this
|
4
|
+
by adding methods for showing classes, objects and so on in hopes that this
|
5
|
+
will create a few teachable moments and enable beginners to explore the
|
6
|
+
mysterious world that IRB represents.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Install at the command line:
|
11
|
+
|
12
|
+
$ gem install explore_rb
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
$ irb
|
17
|
+
$ require 'explore_rb'
|
18
|
+
|
19
|
+
### Listing Classes
|
20
|
+
|
21
|
+
List the classes that are currently defined by typing:
|
22
|
+
|
23
|
+
$ classes
|
24
|
+
|
25
|
+
### Listing Objects
|
26
|
+
|
27
|
+
A hash containing the class and the number of objects that exist in memory is returned by typing:
|
28
|
+
|
29
|
+
$ objects
|
30
|
+
|
31
|
+
### Retrieving Objects
|
32
|
+
|
33
|
+
To retrieve all of the objects of a given type use 'get_objects':
|
34
|
+
|
35
|
+
$ class Book; end
|
36
|
+
$ Book.new
|
37
|
+
$ get_objects(Book)
|
38
|
+
$ => [<#Book>]
|
39
|
+
|
40
|
+
### Listing installed gems
|
41
|
+
|
42
|
+
As you might expect, list gems with:
|
43
|
+
|
44
|
+
$ gems
|
45
|
+
|
46
|
+
### Listing Symbols
|
47
|
+
|
48
|
+
You can get an array of all existing symbols with:
|
49
|
+
|
50
|
+
$ symbols
|
51
|
+
|
52
|
+
### Visualizing code execution
|
53
|
+
|
54
|
+
An SVG file showing the various function calls will be written to the desktop
|
55
|
+
when 'draw_this' is called with a block. This functionality is provided by the
|
56
|
+
Traceur gem. Usage looks like this:
|
57
|
+
|
58
|
+
$ draw_this do
|
59
|
+
$ # some code that has some method calls
|
60
|
+
$ end
|
61
|
+
|
62
|
+
Be conservative with what you put inside that block. Its really easy to end up
|
63
|
+
with an SVG file that is so big that no application can open it. The lines and
|
64
|
+
fonts are as small as possible since there can be a tonne of stuff written in
|
65
|
+
there. Consequently Inkscape is probably the best choice to view the files
|
66
|
+
because you can zoom in lots.
|
67
|
+
|
68
|
+
### Listing variables
|
69
|
+
|
70
|
+
The greeting message displayed when this library is required mentions
|
71
|
+
'local_variables'. This is an existing Ruby method, and not one supplied by
|
72
|
+
this library but it was worth pointing out since fits in with what this library
|
73
|
+
is trying to accomplish.
|
74
|
+
|
75
|
+
## Contributing
|
76
|
+
|
77
|
+
1. Fork it
|
78
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
79
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
80
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
81
|
+
5. Create new Pull Request
|
82
|
+
|
83
|
+
## License
|
84
|
+
|
85
|
+
(The MIT License)
|
86
|
+
|
87
|
+
Copyright (c) 2013 Mike Williamson
|
88
|
+
|
89
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
90
|
+
a copy of this software and associated documentation files (the
|
91
|
+
"Software"), to deal in the Software without restriction, including
|
92
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
93
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
94
|
+
permit persons to whom the Software is furnished to do so, subject to
|
95
|
+
the following conditions:
|
96
|
+
|
97
|
+
The above copyright notice and this permission notice shall be
|
98
|
+
included in all copies or substantial portions of the Software.
|
99
|
+
|
100
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
101
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
102
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
103
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
104
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
105
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
106
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
107
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/explore_rb.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'explore_rb/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "explore_rb"
|
8
|
+
gem.version = ExploreRb::VERSION
|
9
|
+
gem.authors = ["Mike Williamson"]
|
10
|
+
gem.email = ["blessedbyvirtuosity@gmail.com"]
|
11
|
+
gem.description = "This gem extends the main object with helper methods to help beginners explore the Ruby environment when using IRB."
|
12
|
+
gem.summary = "Helper methods for exploring Ruby via IRB"
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
gem.add_dependency "traceur"
|
20
|
+
end
|
data/lib/explore_rb.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'traceur'
|
2
|
+
require "explore_rb/version"
|
3
|
+
|
4
|
+
module ExploreRb
|
5
|
+
|
6
|
+
include GC
|
7
|
+
|
8
|
+
def self.extended base
|
9
|
+
puts "Use the following commands to look around:"
|
10
|
+
puts "classes, objects, get_objects, symbols, local_variables, gems, draw_this, help"
|
11
|
+
end
|
12
|
+
|
13
|
+
def classes
|
14
|
+
(Object.constants - [:RUBY_COPYRIGHT, :RUBY_DESCRIPTION, :RUBY_ENGINE, :RUBY_PATCHLEVEL, :RUBY_PLATFORM, :RUBY_RELEASE_DATE, :RUBY_REVISION, :RUBY_VERSION, :CROSS_COMPILING ]).sort
|
15
|
+
end
|
16
|
+
|
17
|
+
def objects
|
18
|
+
objects = Hash.new {0}
|
19
|
+
ObjectSpace.each_object{|obj| objects[obj.class] += 1 }
|
20
|
+
objects
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_objects klass
|
24
|
+
requested_klass = []
|
25
|
+
ObjectSpace.each_object{|o| requested_klass << ObjectSpace._id2ref(o.object_id) if o.class == klass}
|
26
|
+
requested_klass
|
27
|
+
end
|
28
|
+
|
29
|
+
def symbols
|
30
|
+
Symbol.all_symbols
|
31
|
+
end
|
32
|
+
|
33
|
+
def gems
|
34
|
+
gems = {}
|
35
|
+
Gem::Specification.each{|s| gems[s.name]= s.gem_dir.gsub(ENV['HOME'], "~") }
|
36
|
+
gems
|
37
|
+
end
|
38
|
+
|
39
|
+
def draw_this &block
|
40
|
+
path = "#{ENV['HOME']}/Desktop"
|
41
|
+
Traceur.watch_paths('.+', path, &block)
|
42
|
+
puts "File saved in #{path}."
|
43
|
+
end
|
44
|
+
|
45
|
+
def collect_garbage
|
46
|
+
GC.stress = true # enable hyperactive garbage collection
|
47
|
+
garbage_collect
|
48
|
+
GC.stress = false
|
49
|
+
#puts "Dumped #{GC.stat[:total_freed_object]} objects from memory"
|
50
|
+
GC.stat
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
# add exploreRb methods to the main object
|
57
|
+
self.extend ExploreRb
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: explore_rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike Williamson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-03-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: traceur
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: This gem extends the main object with helper methods to help beginners
|
28
|
+
explore the Ruby environment when using IRB.
|
29
|
+
email:
|
30
|
+
- blessedbyvirtuosity@gmail.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- .gitignore
|
36
|
+
- Gemfile
|
37
|
+
- LICENSE.txt
|
38
|
+
- README.md
|
39
|
+
- Rakefile
|
40
|
+
- explore_rb.gemspec
|
41
|
+
- lib/explore_rb.rb
|
42
|
+
- lib/explore_rb/version.rb
|
43
|
+
homepage: ''
|
44
|
+
licenses: []
|
45
|
+
metadata: {}
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 2.0.0
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: Helper methods for exploring Ruby via IRB
|
66
|
+
test_files: []
|