rubytutor 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +188 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/descriptions/Array.txt +10 -0
- data/lib/descriptions/Bignum.txt +9 -0
- data/lib/descriptions/Class.txt +16 -0
- data/lib/descriptions/FalseClass.txt +5 -0
- data/lib/descriptions/Fixnum.txt +15 -0
- data/lib/descriptions/Float.txt +5 -0
- data/lib/descriptions/Hash.txt +12 -0
- data/lib/descriptions/Module.txt +24 -0
- data/lib/descriptions/NilClass.txt +5 -0
- data/lib/descriptions/Proc.txt +16 -0
- data/lib/descriptions/Range.txt +14 -0
- data/lib/descriptions/Regexp.txt +17 -0
- data/lib/descriptions/String.txt +4 -0
- data/lib/descriptions/Struct.txt +15 -0
- data/lib/descriptions/Symbol.txt +9 -0
- data/lib/descriptions/TrueClass.txt +5 -0
- data/lib/descriptions/blank.txt +1 -0
- data/lib/descriptions/intro.txt +1 -0
- data/lib/descriptions/last.txt +3 -0
- data/lib/rubytutor.rb +121 -0
- data/lib/rubytutor/version.rb +3 -0
- data/rubytutor.gemspec +36 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 16311ce192b69336c7ab2c5fac0deb318d0bfc61
|
4
|
+
data.tar.gz: '002384cd7122ee0e1d7df1e5cf29b88dd0e7a442'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7228e5e6b0db3b937811d0dafbac60cd4266adc9e9f1528fd3278721bacb78da3fd99d7f3a1dcc6f75426118e44bf970c236b9d714e18b3c8df1a80b545f2790
|
7
|
+
data.tar.gz: 71de1d1972fe5dc7e0bba1334326db8efa9246469d43504e2a955ddee7d5bfc609b166ec8f977839d69126352951a122a52c445e50b4a769e3f47271ea4ac7b9
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Sunny
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,188 @@
|
|
1
|
+
# RubyTutor
|
2
|
+
|
3
|
+
RubyTutor is an irb tool to help new developers and developers new to using Ruby on the fundamentals of the language.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
### IRB
|
8
|
+
|
9
|
+
In order to use it, simply install it:
|
10
|
+
|
11
|
+
$ gem install rubytutor
|
12
|
+
|
13
|
+
Then go into irb and require it:
|
14
|
+
|
15
|
+
$ irb
|
16
|
+
2.3.3 :001 > require 'rubytutor'
|
17
|
+
=> true
|
18
|
+
|
19
|
+
### Other Uses
|
20
|
+
|
21
|
+
While RubyTutor is meant to be an irb tool, far be it from me to disallow others from finding other uses for it.
|
22
|
+
|
23
|
+
If you wish to add RubyTutor to a project, add this line to your application's Gemfile:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
gem 'rubytutor'
|
27
|
+
```
|
28
|
+
|
29
|
+
And then execute:
|
30
|
+
|
31
|
+
$ bundle install
|
32
|
+
|
33
|
+
Or install it yourself as:
|
34
|
+
|
35
|
+
$ gem install rubytutor
|
36
|
+
|
37
|
+
## Usage
|
38
|
+
|
39
|
+
RubyTutor has 4 class methods that can be useful to developers:
|
40
|
+
|
41
|
+
* `RubyTutor.explain_full(object)`
|
42
|
+
* `RubyTutor.explain(object)`
|
43
|
+
* `RubyTutor.describe(object)`
|
44
|
+
* `RubyTutor.available_methods(object, filter)`
|
45
|
+
|
46
|
+
### explain_full
|
47
|
+
|
48
|
+
`explain_full` outputs a list of attributes pertaining to the object passed in.
|
49
|
+
|
50
|
+
Here is a sample output:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
RubyTutor.explain_full 'string'
|
54
|
+
|
55
|
+
# >> Instance of Class: String
|
56
|
+
# >> Value: string
|
57
|
+
# >> Length: 6
|
58
|
+
# >> Mutable? Yes
|
59
|
+
# >> Object ID: 70179170680460
|
60
|
+
# >> Inhertits From: Comparable, Object, Kernel, BasicObject
|
61
|
+
# >>
|
62
|
+
# >> Description:
|
63
|
+
# >> This object is an instance of the String class.
|
64
|
+
# >> A String object is an expression that can hold
|
65
|
+
# >> letters, numbers and all sorts of different characters,
|
66
|
+
# >> as long as they are surrounded by single ('')
|
67
|
+
# >> or double ("") quotes.
|
68
|
+
# >>
|
69
|
+
# >> Type RubyTutor.available_methods String
|
70
|
+
# >> to see all of the methods available.
|
71
|
+
```
|
72
|
+
|
73
|
+
### explain/describe
|
74
|
+
|
75
|
+
`explain` outputs the first half of `explain_full` while `describe` outputs the second half of `explain_full`.
|
76
|
+
|
77
|
+
Examples:
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
RubyTutor.explain 'string'
|
81
|
+
|
82
|
+
# >> Instance of Class: String
|
83
|
+
# >> Value: string
|
84
|
+
# >> Length: 6
|
85
|
+
# >> Mutable? Yes
|
86
|
+
# >> Object ID: 70179170680460
|
87
|
+
# >> Inhertits From: Comparable, Object, Kernel, BasicObject
|
88
|
+
|
89
|
+
RubyTutor.describe 'string'
|
90
|
+
|
91
|
+
# >> Description:
|
92
|
+
# >> This object is an instance of the String class.
|
93
|
+
# >> A String object is an expression that can hold
|
94
|
+
# >> letters, numbers and all sorts of different characters,
|
95
|
+
# >> as long as they are surrounded by single ('')
|
96
|
+
# >> or double ("") quotes.
|
97
|
+
# >>
|
98
|
+
# >> Type RubyTutor.available_methods String
|
99
|
+
# >> to see all of the methods available.
|
100
|
+
```
|
101
|
+
|
102
|
+
All descriptions were copied and edited from [Ruby-Docs](https://ruby-doc.org/)
|
103
|
+
|
104
|
+
Sidenote: When passing in a Hash, use the parentheses notation to avoid an error.
|
105
|
+
|
106
|
+
`RubyTutor.explain({a: 1, b: 2, c: 3})`
|
107
|
+
|
108
|
+
### available_methods
|
109
|
+
|
110
|
+
Lastly, `available_methods` outputs all the available methods for the object passed in. `available_methods` also has an optional filter you can pass in. The filter must be a string and the filter only corresponds to the beginning of the method name. In other words, a filter of `'to'` will return all the methods that begin with `'to'`.
|
111
|
+
|
112
|
+
If another object is used for the filter instead of a string, the program will ignore it and return all available methods for the object passed in.
|
113
|
+
|
114
|
+
Example output:
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
RubyTutor.available_methods BasicObject
|
118
|
+
|
119
|
+
# >> Available Methods:
|
120
|
+
# >> !
|
121
|
+
# >> !=
|
122
|
+
# >> !~
|
123
|
+
# >> <
|
124
|
+
# >> <=
|
125
|
+
# >> <=>
|
126
|
+
# >> ==
|
127
|
+
# >> ===
|
128
|
+
# >> =~
|
129
|
+
# >> >
|
130
|
+
# >> >=
|
131
|
+
# >> __id__
|
132
|
+
# >> __send__
|
133
|
+
# >> allocate
|
134
|
+
# >> ancestors
|
135
|
+
# >> autoload
|
136
|
+
# >> autoload?
|
137
|
+
# >> class
|
138
|
+
# >> class_eval
|
139
|
+
# >> class_exec
|
140
|
+
# >> class_variable_defined?
|
141
|
+
# >> class_variable_get
|
142
|
+
# >> class_variable_set
|
143
|
+
# >> class_variables
|
144
|
+
#...(truncated for brevity)
|
145
|
+
|
146
|
+
RubyTutor.available_methods BasicObject, 'al'
|
147
|
+
|
148
|
+
# >> Available Methods:
|
149
|
+
# >> allocate
|
150
|
+
```
|
151
|
+
|
152
|
+
## Classes Supported
|
153
|
+
|
154
|
+
The classes that are currently supported and have descriptions when `RubyTutor.describe` is called are:
|
155
|
+
|
156
|
+
* Array
|
157
|
+
* Bignum
|
158
|
+
* Class
|
159
|
+
* FalseClass
|
160
|
+
* Fixnum
|
161
|
+
* Float
|
162
|
+
* Hash
|
163
|
+
* Module
|
164
|
+
* NilClass
|
165
|
+
* Proc
|
166
|
+
* Range
|
167
|
+
* Regexp
|
168
|
+
* String
|
169
|
+
* Struct
|
170
|
+
* Symbol
|
171
|
+
* TrueClass
|
172
|
+
|
173
|
+
Any other class will return `No further description available at this time.` as a description.
|
174
|
+
|
175
|
+
## Development
|
176
|
+
|
177
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
178
|
+
|
179
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
180
|
+
|
181
|
+
## Contributing
|
182
|
+
|
183
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sunny-b/RubyTutor.
|
184
|
+
|
185
|
+
|
186
|
+
## License
|
187
|
+
|
188
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "tutor"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
Arrays are ordered and integer-indexed collections
|
2
|
+
of objects. The indexes of Arrays are 0 based, meaning
|
3
|
+
that they start at 0. Negative indexes count back from
|
4
|
+
the last elements in the collection. -1 indicates the
|
5
|
+
last element, -2 is the second to last, and so on. An item
|
6
|
+
is retrieved from the collection using bracket notation ([]).
|
7
|
+
|
8
|
+
Example:
|
9
|
+
arr = [1, 2, 3]
|
10
|
+
arr[0] #=> 1
|
@@ -0,0 +1,9 @@
|
|
1
|
+
Bignum objects hold integers outside the range of
|
2
|
+
Fixnum. Bignum objects are created automatically
|
3
|
+
when integer calculations would otherwise overflow
|
4
|
+
a Fixnum. When a calculation involving Bignum objects
|
5
|
+
returns a result that will fit in a Fixnum, the
|
6
|
+
result is automatically converted. Bignum parameter
|
7
|
+
passing works with references to the object. This is
|
8
|
+
different from the Fixnum class, where the object
|
9
|
+
itself is passed.
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Classes in Ruby are first-class objects and each
|
2
|
+
is an instance of class Class. Each class is also
|
3
|
+
a global constant and can be used in any part of a
|
4
|
+
program. Class names are capitalized to differentiate
|
5
|
+
themselves and to show that they are constants.
|
6
|
+
Creating new classes is simple and fundamental to
|
7
|
+
object oriented programming using Ruby.
|
8
|
+
|
9
|
+
Example:
|
10
|
+
class Name
|
11
|
+
def initialize
|
12
|
+
print "Creating a new instance of #{self.name}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
Name.new #=> "Creating a new instance of Name"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Fixnum objects hold Integer values. If any integer
|
2
|
+
exceeds the Fixnum maximum value on your machine,
|
3
|
+
it will be converted to a Bignum. Fixnum objects
|
4
|
+
have immediate value. This means that when they are
|
5
|
+
assigned or passed as parameters, the actual object
|
6
|
+
is passed, rather than a reference to that object.
|
7
|
+
Fixnum objects are also immutable, meaning that the
|
8
|
+
value assigned to that object id will not change no
|
9
|
+
matter what methods or operations executed. Methods
|
10
|
+
such as '+' or '-' return a new Fixnum and do not
|
11
|
+
affect the original value.
|
12
|
+
|
13
|
+
As a sidenote: any mathematical operations the involve
|
14
|
+
two Integers will return an Integer. Meaning that any
|
15
|
+
decimals that would normally be left over will be rounded.
|
@@ -0,0 +1,12 @@
|
|
1
|
+
Hash objects are similar to Arrays in that they are
|
2
|
+
a collection. However, Hashes are more similar to
|
3
|
+
dictionaries in that they have keys, or terms, that
|
4
|
+
relate to their values, or definitions. Any object can
|
5
|
+
be used as a key, including other hashes. Hashes are
|
6
|
+
known as associative arrays and use bracket notation
|
7
|
+
to retrieve elements. Unlike Arrays, Hashes use the keys
|
8
|
+
to retrieve the values.
|
9
|
+
|
10
|
+
Example:
|
11
|
+
hash = { a: 1, b: 2, c: 3 }
|
12
|
+
hash[:a] #=> 1
|
@@ -0,0 +1,24 @@
|
|
1
|
+
A Module is a collection of methods and constants.
|
2
|
+
Modules are often used as a way to "mixin" methods
|
3
|
+
and constants into different classes that may not
|
4
|
+
have similar inheritance. They are also used for
|
5
|
+
what is known as "namespacing," where you group
|
6
|
+
similar methods or classes. The methods in a module
|
7
|
+
may be instance methods or module methods. Instance
|
8
|
+
methods appear as methods in a class when the module
|
9
|
+
is included, module methods do not. In order to mix
|
10
|
+
a module with a class, the 'Include' method is used.
|
11
|
+
|
12
|
+
Example:
|
13
|
+
module Speak
|
14
|
+
def world
|
15
|
+
puts "Hello World"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Hello
|
20
|
+
include Speak
|
21
|
+
end
|
22
|
+
|
23
|
+
hello = Hello.new
|
24
|
+
hello.world #=> "Hello World"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Proc objects are blocks of code that have been
|
2
|
+
bound to a set of local variables. Once bound,
|
3
|
+
the code may be called in different contexts and
|
4
|
+
still access those variables. Procs can be used
|
5
|
+
like variables themselves and passed to functions
|
6
|
+
as arguments. In order to execute the Proc, the
|
7
|
+
'call' method should be used.
|
8
|
+
|
9
|
+
Example:
|
10
|
+
square = Proc.new {|n| n**2}
|
11
|
+
|
12
|
+
def exec_proc(block, num)
|
13
|
+
block.call(num)
|
14
|
+
end
|
15
|
+
|
16
|
+
exec_proc(square), 6) #=> 36
|
@@ -0,0 +1,14 @@
|
|
1
|
+
A Range object represents an interval—a set of
|
2
|
+
values with a beginning and an end. Ranges may
|
3
|
+
be constructed using the s..e and s...e literals.
|
4
|
+
Ranges constructed using .. run from the beginning to
|
5
|
+
the end inclusively. Those created using ... exclude
|
6
|
+
the end value. When used as an iterator, ranges return
|
7
|
+
each value in the sequence. Range objects are used
|
8
|
+
often in case statements, where the cover? Range
|
9
|
+
method is used to determine is the case value is
|
10
|
+
included in the range.
|
11
|
+
|
12
|
+
Examples:
|
13
|
+
array = (1...5).to_a
|
14
|
+
array[0..-1] => [1, 2, 3, 4]
|
@@ -0,0 +1,17 @@
|
|
1
|
+
A Regexp holds a regular expression, used to match
|
2
|
+
a pattern against strings. Regexps are created using
|
3
|
+
the /.../ literals, and by the Regexp::new
|
4
|
+
constructor. Regular expressions (regexps) are patterns
|
5
|
+
which describe the contents of a string. They’re used
|
6
|
+
for testing whether a string contains a given pattern,
|
7
|
+
or extracting the portions that string. They are
|
8
|
+
created with the /pat/ literals or the
|
9
|
+
Regexp.new constructor. If a string contains the
|
10
|
+
pattern, it is said to 'match'. A literal string
|
11
|
+
matches itself.
|
12
|
+
|
13
|
+
Examples:
|
14
|
+
/hay/ =~ 'haystack' #=> 0
|
15
|
+
/y/.match('haystack') #=> #<MatchData "y">
|
16
|
+
/needle/.match('haystack') #=> nil
|
17
|
+
/hay/.match('haystack') #=> #<MatchData "hay">
|
@@ -0,0 +1,15 @@
|
|
1
|
+
A Struct is a convenient way to bundle a number of
|
2
|
+
attributes together, using accessor methods, without
|
3
|
+
having to write an explicit class. The Struct class
|
4
|
+
is a generator of specific classes, each one of which
|
5
|
+
is defined to hold a set of variables and their
|
6
|
+
accessors. While Modules house behaviors in instance
|
7
|
+
methods, Structs house mainly behaviors in variables
|
8
|
+
and accessors.
|
9
|
+
|
10
|
+
Examples:
|
11
|
+
Customer = Struct.new(:name, :address, :zip)
|
12
|
+
joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
|
13
|
+
joe.name #=> Joe Smith
|
14
|
+
joe.address #=> 123 Maple, Anytown NC
|
15
|
+
joe.zip #=> 12345
|
@@ -0,0 +1,9 @@
|
|
1
|
+
Symbol objects represent names inside the Ruby
|
2
|
+
interpreter. They are generated using the :name
|
3
|
+
literal syntax, and by the various to_sym methods.
|
4
|
+
While :'string' is also an acceptable form of a
|
5
|
+
symbol, this syntax is rarely used and generally
|
6
|
+
frowned upon. Symbols are also known as immutable,
|
7
|
+
meaning that a symbol cannot be changed when it is
|
8
|
+
created, only replaced. This makes Symbols ideal as
|
9
|
+
keys in Hashes.
|
@@ -0,0 +1 @@
|
|
1
|
+
No further description available at this time.
|
@@ -0,0 +1 @@
|
|
1
|
+
This object is an instance of the %{class} class.
|
data/lib/rubytutor.rb
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
require_relative 'rubytutor/version'
|
2
|
+
|
3
|
+
# RubyTutor main class
|
4
|
+
class RubyTutor
|
5
|
+
def self.explain_full(object)
|
6
|
+
puts full_explanation(object).join("\n")
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.describe(object)
|
10
|
+
puts retrieve_description(object)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.explain(object)
|
14
|
+
puts retrieve_explanation(object).join("\n")
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.available_methods(object, filter_str = nil)
|
18
|
+
class_name = object.class == Class ? object : object.class
|
19
|
+
methods = retrieve_methods(class_name, filter_str)
|
20
|
+
|
21
|
+
puts methods
|
22
|
+
end
|
23
|
+
|
24
|
+
private_class_method
|
25
|
+
|
26
|
+
def self.retrieve_methods(class_name, filter_str = nil)
|
27
|
+
method_names = class_name.methods.sort
|
28
|
+
|
29
|
+
if valid?(filter_str)
|
30
|
+
last_index = filter_str.length
|
31
|
+
|
32
|
+
method_names = method_names.map(&:to_s).select do |method|
|
33
|
+
method[0...last_index] == filter_str
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
"Available Methods: \n" + method_names.join("\n").to_s + "\n\n"
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.retrieve_explanation(object)
|
41
|
+
class_name = retrieve_class(object)
|
42
|
+
ancestors = class_name.ancestors[1..-1].join(', ')
|
43
|
+
value = object.nil? ? 'nil' : object
|
44
|
+
|
45
|
+
construct_explain(object, class_name, ancestors, value)
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.construct_explain(object, class_name, ancestors, value)
|
49
|
+
text = []
|
50
|
+
|
51
|
+
text << "Instance of Class: #{class_name}"
|
52
|
+
text << "Value: #{value}"
|
53
|
+
|
54
|
+
variable_text(object, text)
|
55
|
+
|
56
|
+
text << "Mutable? #{object.frozen? ? 'No' : 'Yes'}"
|
57
|
+
text << "Object ID: #{object.object_id}"
|
58
|
+
text << "Inhertits From: #{ancestors}"
|
59
|
+
text << ''
|
60
|
+
end
|
61
|
+
|
62
|
+
# Not pretty, but this is the method that determines which strings will go
|
63
|
+
# Into each 'explain' or 'explain_full' call
|
64
|
+
def self.variable_text(object, text)
|
65
|
+
text << "Return Value: #{object.call}" if need?(object, :call)
|
66
|
+
text << "Source Value: #{object.source}" if need?(object, :source)
|
67
|
+
text << "Members: #{object.members.join(', ')}" if need?(object, :members)
|
68
|
+
text << "Keys: #{object.keys.join(', ')}" if need?(object, :keys)
|
69
|
+
text << "Values: #{object.values.join(', ')}" if need?(object, :values)
|
70
|
+
text << "Length: #{object.length}" if need?(object, :length)
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.need?(object, method_symbol)
|
74
|
+
object.respond_to?(method_symbol)
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.full_explanation(object)
|
78
|
+
full_string = []
|
79
|
+
|
80
|
+
full_string << retrieve_explanation(object)
|
81
|
+
full_string << retrieve_description(object)
|
82
|
+
full_string.flatten
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.retrieve_description(object)
|
86
|
+
class_name = retrieve_class(object)
|
87
|
+
description = ["Description:\n"]
|
88
|
+
files = []
|
89
|
+
|
90
|
+
find(files, class_name)
|
91
|
+
extract_contents(files, description, object, class_name)
|
92
|
+
description.join
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.valid?(letter)
|
96
|
+
letter.respond_to?(:match) ? letter.downcase.match(/[a-z]/) : false
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.retrieve_class(object)
|
100
|
+
object.respond_to?(:members) ? Struct : object.class
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.extract_contents(files, description, object, class_name)
|
104
|
+
files.each do |file_path|
|
105
|
+
File.open(file_path) do |file|
|
106
|
+
file.each do |line|
|
107
|
+
description << format(line, value: object, class: class_name)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def self.find(files, class_name)
|
114
|
+
class_file = File.expand_path("../descriptions/#{class_name}.txt", __FILE__)
|
115
|
+
blank_file = File.expand_path('../descriptions/blank.txt', __FILE__)
|
116
|
+
|
117
|
+
files << File.expand_path('../descriptions/intro.txt', __FILE__)
|
118
|
+
files << (File.file?(class_file) ? class_file : blank_file)
|
119
|
+
files << File.expand_path('../descriptions/last.txt', __FILE__)
|
120
|
+
end
|
121
|
+
end
|
data/rubytutor.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rubytutor/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rubytutor"
|
8
|
+
spec.version = RubyTutor::VERSION
|
9
|
+
spec.authors = ["Sunny"]
|
10
|
+
spec.email = ["sjbeatteay@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{An irb tool to help new developers use Ruby}
|
13
|
+
spec.description = %q{A console tool to help new developers and developers new to Ruby.}
|
14
|
+
spec.homepage = "https://github.com/sunny-b/RubyTutor"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# # to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata['allowed_push_host'] = "http://rubygems.org"
|
21
|
+
# else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
# "public gem pushes."
|
24
|
+
# end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubytutor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sunny
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-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.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
description: A console tool to help new developers and developers new to Ruby.
|
56
|
+
email:
|
57
|
+
- sjbeatteay@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/console
|
69
|
+
- bin/setup
|
70
|
+
- lib/descriptions/Array.txt
|
71
|
+
- lib/descriptions/Bignum.txt
|
72
|
+
- lib/descriptions/Class.txt
|
73
|
+
- lib/descriptions/FalseClass.txt
|
74
|
+
- lib/descriptions/Fixnum.txt
|
75
|
+
- lib/descriptions/Float.txt
|
76
|
+
- lib/descriptions/Hash.txt
|
77
|
+
- lib/descriptions/Module.txt
|
78
|
+
- lib/descriptions/NilClass.txt
|
79
|
+
- lib/descriptions/Proc.txt
|
80
|
+
- lib/descriptions/Range.txt
|
81
|
+
- lib/descriptions/Regexp.txt
|
82
|
+
- lib/descriptions/String.txt
|
83
|
+
- lib/descriptions/Struct.txt
|
84
|
+
- lib/descriptions/Symbol.txt
|
85
|
+
- lib/descriptions/TrueClass.txt
|
86
|
+
- lib/descriptions/blank.txt
|
87
|
+
- lib/descriptions/intro.txt
|
88
|
+
- lib/descriptions/last.txt
|
89
|
+
- lib/rubytutor.rb
|
90
|
+
- lib/rubytutor/version.rb
|
91
|
+
- rubytutor.gemspec
|
92
|
+
homepage: https://github.com/sunny-b/RubyTutor
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.6.8
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: An irb tool to help new developers use Ruby
|
116
|
+
test_files: []
|