pretty_irb 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/00-MANIFEST.md +356 -0
- data/ADVANCED_FEATURES.md +440 -0
- data/AI_HELP.md +408 -0
- data/AI_QUICK_START.md +247 -0
- data/COMPLETE.md +421 -0
- data/EXAMPLES.md +206 -0
- data/FEATURE_SHOWCASE.md +441 -0
- data/FILE_STRUCTURE.md +231 -0
- data/Gemfile +3 -0
- data/IMPLEMENTATION_COMPLETE.md +309 -0
- data/INDEX.md +708 -0
- data/INSTALL.md +250 -0
- data/LICENSE.txt +21 -0
- data/PUBLISH_TO_RUBYGEMS.md +466 -0
- data/QUICKSTART.md +70 -0
- data/QUICK_REFERENCE.md +253 -0
- data/README.md +251 -0
- data/Rakefile +6 -0
- data/SETUP.md +209 -0
- data/START_HERE.md +462 -0
- data/SUMMARY.md +372 -0
- data/WELCOME.md +300 -0
- data/WHAT_IS_NEW.md +324 -0
- data/exe/irb1 +6 -0
- data/exe/pretty_irb +6 -0
- data/lib/pretty_irb/ai_helper.rb +842 -0
- data/lib/pretty_irb/auto_corrector.rb +76 -0
- data/lib/pretty_irb/benchmarker.rb +94 -0
- data/lib/pretty_irb/cheat_sheet.rb +476 -0
- data/lib/pretty_irb/formatter.rb +66 -0
- data/lib/pretty_irb/history_manager.rb +97 -0
- data/lib/pretty_irb/shell.rb +387 -0
- data/lib/pretty_irb/snippet_manager.rb +119 -0
- data/lib/pretty_irb/variable_inspector.rb +146 -0
- data/lib/pretty_irb/version.rb +3 -0
- data/lib/pretty_irb.rb +26 -0
- metadata +200 -0
data/AI_HELP.md
ADDED
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
# Pretty IRB - AI Helper Features
|
|
2
|
+
|
|
3
|
+
## 🤖 AI Help Commands
|
|
4
|
+
|
|
5
|
+
Pretty IRB now includes built-in AI-powered help features to make learning Ruby easier!
|
|
6
|
+
|
|
7
|
+
### Overview
|
|
8
|
+
|
|
9
|
+
Instead of searching the web or documentation, use these commands directly in Pretty IRB:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
?explain(method) # Explain how a Ruby method works
|
|
13
|
+
?example(topic) # Get code examples for concepts
|
|
14
|
+
?debug(code) # Analyze your code for potential issues
|
|
15
|
+
?practices(topic) # Learn best practices
|
|
16
|
+
?ref(keyword) # Quick reference guides
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 📚 Available Commands
|
|
22
|
+
|
|
23
|
+
### 1. `?explain(method_name)` - Method Explanations
|
|
24
|
+
|
|
25
|
+
Learn how specific Ruby methods work with examples.
|
|
26
|
+
|
|
27
|
+
**Available methods:**
|
|
28
|
+
- `map` - Transform array elements
|
|
29
|
+
- `select` / `filter` - Filter array elements
|
|
30
|
+
- `each` - Iterate without transformation
|
|
31
|
+
- `reduce` / `inject` - Combine into single value
|
|
32
|
+
- `find` / `detect` - Find first matching element
|
|
33
|
+
- `merge` - Combine hashes
|
|
34
|
+
- `keys` / `values` - Get hash keys/values
|
|
35
|
+
- `gsub` / `sub` - Replace in strings
|
|
36
|
+
- `split` / `join` - String ↔ Array conversion
|
|
37
|
+
|
|
38
|
+
**Examples:**
|
|
39
|
+
|
|
40
|
+
```ruby
|
|
41
|
+
pretty_irb >> ?explain(map)
|
|
42
|
+
🎯 map method: Transforms each element of an array
|
|
43
|
+
|
|
44
|
+
Syntax: array.map { |item| transformation }
|
|
45
|
+
|
|
46
|
+
Example:
|
|
47
|
+
[1, 2, 3].map { |x| x * 2 }
|
|
48
|
+
=> [2, 4, 6]
|
|
49
|
+
|
|
50
|
+
Key points:
|
|
51
|
+
• Returns a NEW array (doesn't modify original)
|
|
52
|
+
• Applies block to each element
|
|
53
|
+
• Commonly used for data transformation
|
|
54
|
+
|
|
55
|
+
pretty_irb >> ?explain(select)
|
|
56
|
+
🎯 select method: Filters array based on condition
|
|
57
|
+
|
|
58
|
+
Syntax: array.select { |item| condition }
|
|
59
|
+
|
|
60
|
+
Example:
|
|
61
|
+
[1, 2, 3, 4, 5].select { |x| x > 2 }
|
|
62
|
+
=> [3, 4, 5]
|
|
63
|
+
|
|
64
|
+
Key points:
|
|
65
|
+
• Returns NEW array with matching elements
|
|
66
|
+
• Returns empty array if nothing matches
|
|
67
|
+
• Use for filtering/querying data
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
### 2. `?example(topic)` - Code Examples
|
|
73
|
+
|
|
74
|
+
Get code examples for learning concepts.
|
|
75
|
+
|
|
76
|
+
**Available topics:**
|
|
77
|
+
- `loop` - Iteration patterns
|
|
78
|
+
- `condition` - If/elsif/case statements
|
|
79
|
+
- `class` - Class definition
|
|
80
|
+
- `method` - Method definition
|
|
81
|
+
- `array` - Array operations
|
|
82
|
+
- `hash` - Hash operations
|
|
83
|
+
- `string` - String operations
|
|
84
|
+
- `error` - Error handling
|
|
85
|
+
- `block` - Blocks, procs, lambdas
|
|
86
|
+
|
|
87
|
+
**Examples:**
|
|
88
|
+
|
|
89
|
+
```ruby
|
|
90
|
+
pretty_irb >> ?example(class)
|
|
91
|
+
📚 Class Definition Example:
|
|
92
|
+
|
|
93
|
+
class Person
|
|
94
|
+
attr_accessor :name, :age
|
|
95
|
+
|
|
96
|
+
def initialize(name, age)
|
|
97
|
+
@name = name
|
|
98
|
+
@age = age
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def info
|
|
102
|
+
"#{@name} is #{@age} years old"
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
person = Person.new("Alice", 30)
|
|
107
|
+
puts person.info
|
|
108
|
+
|
|
109
|
+
pretty_irb >> ?example(error)
|
|
110
|
+
📚 Error Handling Examples:
|
|
111
|
+
|
|
112
|
+
Basic rescue:
|
|
113
|
+
begin
|
|
114
|
+
result = 10 / 0
|
|
115
|
+
rescue ZeroDivisionError
|
|
116
|
+
puts "Cannot divide by zero"
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
Multiple rescue clauses:
|
|
120
|
+
begin
|
|
121
|
+
risky_operation
|
|
122
|
+
rescue TypeError
|
|
123
|
+
puts "Type error"
|
|
124
|
+
rescue ArgumentError
|
|
125
|
+
puts "Wrong arguments"
|
|
126
|
+
end
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
### 3. `?debug(code)` - Code Analysis
|
|
132
|
+
|
|
133
|
+
Get suggestions for improving your code.
|
|
134
|
+
|
|
135
|
+
**What it checks:**
|
|
136
|
+
- Missing error handling
|
|
137
|
+
- Potential nil references
|
|
138
|
+
- Code complexity
|
|
139
|
+
- Risky operations
|
|
140
|
+
|
|
141
|
+
**Example:**
|
|
142
|
+
|
|
143
|
+
```ruby
|
|
144
|
+
pretty_irb >> ?debug("[1,2,3][0]")
|
|
145
|
+
📊 Code Analysis:
|
|
146
|
+
|
|
147
|
+
Complexity: Simple
|
|
148
|
+
|
|
149
|
+
⚠️ Potential Issues:
|
|
150
|
+
• Missing error handling
|
|
151
|
+
|
|
152
|
+
💡 Suggestions:
|
|
153
|
+
• Consider using safe navigation operator (&.) for chained calls
|
|
154
|
+
• Add error handling with begin/rescue/end
|
|
155
|
+
|
|
156
|
+
pretty_irb >> ?debug("user.name.upcase")
|
|
157
|
+
📊 Code Analysis:
|
|
158
|
+
|
|
159
|
+
Complexity: Simple
|
|
160
|
+
|
|
161
|
+
⚠️ Potential Issues:
|
|
162
|
+
• Potential nil reference
|
|
163
|
+
|
|
164
|
+
💡 Suggestions:
|
|
165
|
+
• Consider using safe navigation operator (&.) for chained calls
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
### 4. `?practices(topic)` - Best Practices
|
|
171
|
+
|
|
172
|
+
Learn Ruby best practices and conventions.
|
|
173
|
+
|
|
174
|
+
**Available topics:**
|
|
175
|
+
- `naming` - Variable, method, class naming conventions
|
|
176
|
+
- `performance` - Performance optimization tips
|
|
177
|
+
- `readability` - Code readability tips
|
|
178
|
+
- `testing` - Testing best practices
|
|
179
|
+
- `security` - Security tips
|
|
180
|
+
- (default) - General best practices
|
|
181
|
+
|
|
182
|
+
**Examples:**
|
|
183
|
+
|
|
184
|
+
```ruby
|
|
185
|
+
pretty_irb >> ?practices(naming)
|
|
186
|
+
✨ Naming Conventions Best Practices:
|
|
187
|
+
|
|
188
|
+
Variables:
|
|
189
|
+
• Use snake_case: user_name, total_price
|
|
190
|
+
• Be descriptive: total_price instead of tp
|
|
191
|
+
• Avoid single letters (except i, j for loops)
|
|
192
|
+
|
|
193
|
+
Methods:
|
|
194
|
+
• Use snake_case: calculate_total(), user_exists?()
|
|
195
|
+
• Predicates end with ?: valid?(), empty?()
|
|
196
|
+
• Dangerous methods end with !: delete!(), save!()
|
|
197
|
+
|
|
198
|
+
Classes:
|
|
199
|
+
• Use PascalCase: User, ShoppingCart, UserProfile
|
|
200
|
+
• Nouns, not verbs
|
|
201
|
+
|
|
202
|
+
Avoid:
|
|
203
|
+
✗ Hungarian notation: strName, intAge
|
|
204
|
+
✗ Non-English: cena, utilisateur
|
|
205
|
+
✗ Misleading names: data, result, temp
|
|
206
|
+
|
|
207
|
+
pretty_irb >> ?practices(performance)
|
|
208
|
+
⚡ Performance Tips:
|
|
209
|
+
|
|
210
|
+
Array Operations:
|
|
211
|
+
• Use each instead of map if you don't need results
|
|
212
|
+
• Use find instead of select if you need first match
|
|
213
|
+
• Avoid nested loops when possible
|
|
214
|
+
|
|
215
|
+
String Operations:
|
|
216
|
+
• Use String#freeze for constants
|
|
217
|
+
• Use single quotes for static strings
|
|
218
|
+
• Avoid string concatenation in loops (use array join)
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
### 5. `?ref(keyword)` - Quick Reference
|
|
224
|
+
|
|
225
|
+
Get quick reference guides.
|
|
226
|
+
|
|
227
|
+
**Available references:**
|
|
228
|
+
- `operators` - All Ruby operators
|
|
229
|
+
- `symbols` - Symbols usage
|
|
230
|
+
- `variables` - Variable types
|
|
231
|
+
- `methods` - Common methods by type
|
|
232
|
+
|
|
233
|
+
**Examples:**
|
|
234
|
+
|
|
235
|
+
```ruby
|
|
236
|
+
pretty_irb >> ?ref(operators)
|
|
237
|
+
📋 Ruby Operators Reference:
|
|
238
|
+
|
|
239
|
+
Arithmetic:
|
|
240
|
+
+ (addition) - (subtraction) * (multiplication)
|
|
241
|
+
/ (division) % (modulo) ** (exponentiation)
|
|
242
|
+
|
|
243
|
+
Comparison:
|
|
244
|
+
== (equal) != (not equal) < (less than)
|
|
245
|
+
> (greater than) <= (less than or equal)
|
|
246
|
+
>= (greater than or equal)
|
|
247
|
+
<=> (spaceship - comparison)
|
|
248
|
+
|
|
249
|
+
Logical:
|
|
250
|
+
&& (and) || (or) ! (not)
|
|
251
|
+
and, or, not (lower precedence)
|
|
252
|
+
|
|
253
|
+
pretty_irb >> ?ref(variables)
|
|
254
|
+
📋 Variable Types Reference:
|
|
255
|
+
|
|
256
|
+
Local Variables:
|
|
257
|
+
name = "Alice"
|
|
258
|
+
# Scoped to current context
|
|
259
|
+
|
|
260
|
+
Instance Variables:
|
|
261
|
+
@name = "Alice"
|
|
262
|
+
# Scoped to object instance
|
|
263
|
+
|
|
264
|
+
Class Variables:
|
|
265
|
+
@@count = 0
|
|
266
|
+
# Shared by all instances of class
|
|
267
|
+
|
|
268
|
+
Global Variables:
|
|
269
|
+
$global = "danger"
|
|
270
|
+
# Avoid! Use sparingly
|
|
271
|
+
|
|
272
|
+
Constants:
|
|
273
|
+
MAX_SIZE = 100
|
|
274
|
+
# Should not be changed
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
---
|
|
278
|
+
|
|
279
|
+
## 🎯 Common Use Cases
|
|
280
|
+
|
|
281
|
+
### Learning a New Method
|
|
282
|
+
|
|
283
|
+
```ruby
|
|
284
|
+
# I want to learn about the map method
|
|
285
|
+
pretty_irb >> ?explain(map)
|
|
286
|
+
|
|
287
|
+
# I want to see an example of using blocks
|
|
288
|
+
pretty_irb >> ?example(block)
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### Reviewing Best Practices
|
|
292
|
+
|
|
293
|
+
```ruby
|
|
294
|
+
# What's the best way to name variables?
|
|
295
|
+
pretty_irb >> ?practices(naming)
|
|
296
|
+
|
|
297
|
+
# How should I write more performant code?
|
|
298
|
+
pretty_irb >> ?practices(performance)
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
### Understanding Concepts
|
|
302
|
+
|
|
303
|
+
```ruby
|
|
304
|
+
# Show me how to handle errors
|
|
305
|
+
pretty_irb >> ?example(error)
|
|
306
|
+
|
|
307
|
+
# What are Ruby's operators?
|
|
308
|
+
pretty_irb >> ?ref(operators)
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### Debugging Code
|
|
312
|
+
|
|
313
|
+
```ruby
|
|
314
|
+
# Is this risky code?
|
|
315
|
+
pretty_irb >> ?debug("user.profile.name.upcase")
|
|
316
|
+
|
|
317
|
+
# Does this follow best practices?
|
|
318
|
+
pretty_irb >> ?practices(security)
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
---
|
|
322
|
+
|
|
323
|
+
## 💡 Tips & Tricks
|
|
324
|
+
|
|
325
|
+
### Combine with Regular Code
|
|
326
|
+
|
|
327
|
+
```ruby
|
|
328
|
+
# Learn a method
|
|
329
|
+
pretty_irb >> ?explain(select)
|
|
330
|
+
|
|
331
|
+
# Try it immediately
|
|
332
|
+
pretty_irb >> [1, 2, 3, 4, 5].select { |x| x > 2 }
|
|
333
|
+
=> [3, 4, 5]
|
|
334
|
+
|
|
335
|
+
# Get more examples
|
|
336
|
+
pretty_irb >> ?example(array)
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
### Use for Self-Study
|
|
340
|
+
|
|
341
|
+
```ruby
|
|
342
|
+
# Follow a learning path:
|
|
343
|
+
pretty_irb >> ?example(method) # Learn method syntax
|
|
344
|
+
pretty_irb >> ?explain(map) # Learn a specific method
|
|
345
|
+
pretty_irb >> ?practices(readability) # Learn best practices
|
|
346
|
+
pretty_irb >> ?ref(operators) # Check references
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
### Review Before Coding
|
|
350
|
+
|
|
351
|
+
```ruby
|
|
352
|
+
# Check best practices before starting
|
|
353
|
+
pretty_irb >> ?practices(naming)
|
|
354
|
+
|
|
355
|
+
# Get examples of similar code
|
|
356
|
+
pretty_irb >> ?example(class)
|
|
357
|
+
|
|
358
|
+
# Check for potential issues
|
|
359
|
+
pretty_irb >> ?debug(code_snippet)
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
---
|
|
363
|
+
|
|
364
|
+
## 🎨 Features
|
|
365
|
+
|
|
366
|
+
- ✅ **Interactive Learning** - Learn Ruby interactively
|
|
367
|
+
- ✅ **No Context Switching** - Stay in your REPL
|
|
368
|
+
- ✅ **Rich Examples** - Real code examples
|
|
369
|
+
- ✅ **Best Practices** - Industry-standard tips
|
|
370
|
+
- ✅ **Quick Reference** - Fast lookup
|
|
371
|
+
- ✅ **Code Analysis** - Spot potential issues
|
|
372
|
+
- ✅ **Beginner Friendly** - Great for learning
|
|
373
|
+
|
|
374
|
+
---
|
|
375
|
+
|
|
376
|
+
## 📖 Method Reference
|
|
377
|
+
|
|
378
|
+
| Command | Purpose | Example |
|
|
379
|
+
|---------|---------|---------|
|
|
380
|
+
| `?explain()` | How a method works | `?explain(map)` |
|
|
381
|
+
| `?example()` | Code examples | `?example(class)` |
|
|
382
|
+
| `?debug()` | Analyze code | `?debug("code")` |
|
|
383
|
+
| `?practices()` | Best practices | `?practices(naming)` |
|
|
384
|
+
| `?ref()` | Quick reference | `?ref(operators)` |
|
|
385
|
+
|
|
386
|
+
---
|
|
387
|
+
|
|
388
|
+
## 🚀 Getting Started
|
|
389
|
+
|
|
390
|
+
1. Start Pretty IRB: `ruby bin/console`
|
|
391
|
+
2. Type `help` to see all commands
|
|
392
|
+
3. Try: `?explain(map)`
|
|
393
|
+
4. Learn and practice!
|
|
394
|
+
|
|
395
|
+
---
|
|
396
|
+
|
|
397
|
+
## 🤝 Feedback
|
|
398
|
+
|
|
399
|
+
Love the AI helper? Have suggestions?
|
|
400
|
+
|
|
401
|
+
- Try all the examples
|
|
402
|
+
- Combine with actual Ruby code
|
|
403
|
+
- Use for learning and reference
|
|
404
|
+
- Share your favorite features!
|
|
405
|
+
|
|
406
|
+
---
|
|
407
|
+
|
|
408
|
+
**Happy Learning! 🎓**
|
data/AI_QUICK_START.md
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
# AI Helper - Quick Start Guide
|
|
2
|
+
|
|
3
|
+
## 🤖 What is Pretty IRB's AI Helper?
|
|
4
|
+
|
|
5
|
+
Pretty IRB now includes built-in AI-powered learning features! Instead of googling or reading documentation, get instant help right in your REPL.
|
|
6
|
+
|
|
7
|
+
## ⚡ 30-Second Quick Start
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
# Start Pretty IRB
|
|
11
|
+
ruby bin/console
|
|
12
|
+
|
|
13
|
+
# Learn a method
|
|
14
|
+
pretty_irb >> ?explain(map)
|
|
15
|
+
|
|
16
|
+
# Get examples
|
|
17
|
+
pretty_irb >> ?example(class)
|
|
18
|
+
|
|
19
|
+
# Check best practices
|
|
20
|
+
pretty_irb >> ?practices(naming)
|
|
21
|
+
|
|
22
|
+
# Analyze code
|
|
23
|
+
pretty_irb >> ?debug("risky_code")
|
|
24
|
+
|
|
25
|
+
# Quick reference
|
|
26
|
+
pretty_irb >> ?ref(operators)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## 📚 5 AI Commands
|
|
30
|
+
|
|
31
|
+
### 1. Learn Methods: `?explain(name)`
|
|
32
|
+
|
|
33
|
+
```ruby
|
|
34
|
+
pretty_irb >> ?explain(map)
|
|
35
|
+
pretty_irb >> ?explain(select)
|
|
36
|
+
pretty_irb >> ?explain(reduce)
|
|
37
|
+
pretty_irb >> ?explain(merge)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Available methods: map, select, each, reduce, find, merge, keys, values, gsub, split, join
|
|
41
|
+
|
|
42
|
+
### 2. Code Examples: `?example(topic)`
|
|
43
|
+
|
|
44
|
+
```ruby
|
|
45
|
+
pretty_irb >> ?example(class)
|
|
46
|
+
pretty_irb >> ?example(loop)
|
|
47
|
+
pretty_irb >> ?example(error)
|
|
48
|
+
pretty_irb >> ?example(array)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Available topics: class, method, array, hash, string, loop, condition, error, block
|
|
52
|
+
|
|
53
|
+
### 3. Analyze Code: `?debug(code)`
|
|
54
|
+
|
|
55
|
+
```ruby
|
|
56
|
+
pretty_irb >> ?debug("1/0")
|
|
57
|
+
pretty_irb >> ?debug("user.name.upcase")
|
|
58
|
+
pretty_irb >> ?debug("File.read('path')")
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Checks for: nil references, error handling, risky operations
|
|
62
|
+
|
|
63
|
+
### 4. Best Practices: `?practices(topic)`
|
|
64
|
+
|
|
65
|
+
```ruby
|
|
66
|
+
pretty_irb >> ?practices(naming)
|
|
67
|
+
pretty_irb >> ?practices(performance)
|
|
68
|
+
pretty_irb >> ?practices(testing)
|
|
69
|
+
pretty_irb >> ?practices(security)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Available topics: naming, performance, readability, testing, security
|
|
73
|
+
|
|
74
|
+
### 5. Quick Reference: `?ref(keyword)`
|
|
75
|
+
|
|
76
|
+
```ruby
|
|
77
|
+
pretty_irb >> ?ref(operators)
|
|
78
|
+
pretty_irb >> ?ref(symbols)
|
|
79
|
+
pretty_irb >> ?ref(variables)
|
|
80
|
+
pretty_irb >> ?ref(methods)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## 🎯 Real-World Examples
|
|
86
|
+
|
|
87
|
+
### Learning to Use map
|
|
88
|
+
|
|
89
|
+
```ruby
|
|
90
|
+
# Step 1: Learn about it
|
|
91
|
+
pretty_irb >> ?explain(map)
|
|
92
|
+
|
|
93
|
+
# Step 2: Try it
|
|
94
|
+
pretty_irb >> [1, 2, 3].map { |x| x * 2 }
|
|
95
|
+
=> [2, 4, 6]
|
|
96
|
+
|
|
97
|
+
# Step 3: Get more examples
|
|
98
|
+
pretty_irb >> ?example(array)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Understanding Classes
|
|
102
|
+
|
|
103
|
+
```ruby
|
|
104
|
+
# Step 1: See an example
|
|
105
|
+
pretty_irb >> ?example(class)
|
|
106
|
+
|
|
107
|
+
# Step 2: Create your own
|
|
108
|
+
pretty_irb >> class Person
|
|
109
|
+
pretty_irb >> attr_accessor :name
|
|
110
|
+
pretty_irb >> def initialize(name)
|
|
111
|
+
pretty_irb >> @name = name
|
|
112
|
+
pretty_irb >> end
|
|
113
|
+
pretty_irb >> end
|
|
114
|
+
|
|
115
|
+
# Step 3: Test it
|
|
116
|
+
pretty_irb >> person = Person.new("Alice")
|
|
117
|
+
pretty_irb >> person.name
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Before Writing Code
|
|
121
|
+
|
|
122
|
+
```ruby
|
|
123
|
+
# Step 1: Check naming conventions
|
|
124
|
+
pretty_irb >> ?practices(naming)
|
|
125
|
+
|
|
126
|
+
# Step 2: Check operators you'll use
|
|
127
|
+
pretty_irb >> ?ref(operators)
|
|
128
|
+
|
|
129
|
+
# Step 3: Get example code
|
|
130
|
+
pretty_irb >> ?example(method)
|
|
131
|
+
|
|
132
|
+
# Step 4: Write confident code!
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## 💡 Pro Tips
|
|
138
|
+
|
|
139
|
+
### 1. Learn While Coding
|
|
140
|
+
|
|
141
|
+
```ruby
|
|
142
|
+
# Get confused by a method?
|
|
143
|
+
pretty_irb >> ?explain(method_name)
|
|
144
|
+
|
|
145
|
+
# Try immediately in same session!
|
|
146
|
+
pretty_irb >> [1, 2, 3].method_name { ... }
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### 2. Reference Before Coding
|
|
150
|
+
|
|
151
|
+
```ruby
|
|
152
|
+
# What operators are available?
|
|
153
|
+
pretty_irb >> ?ref(operators)
|
|
154
|
+
|
|
155
|
+
# How should I name things?
|
|
156
|
+
pretty_irb >> ?practices(naming)
|
|
157
|
+
|
|
158
|
+
# What are symbols?
|
|
159
|
+
pretty_irb >> ?ref(symbols)
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### 3. Debug Safely
|
|
163
|
+
|
|
164
|
+
```ruby
|
|
165
|
+
# Is this code risky?
|
|
166
|
+
pretty_irb >> ?debug("array[0].method_name")
|
|
167
|
+
|
|
168
|
+
# How should I handle errors?
|
|
169
|
+
pretty_irb >> ?example(error)
|
|
170
|
+
|
|
171
|
+
# What are best practices?
|
|
172
|
+
pretty_irb >> ?practices(security)
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### 4. Create Learning Sequences
|
|
176
|
+
|
|
177
|
+
```ruby
|
|
178
|
+
# Complete learning path:
|
|
179
|
+
pretty_irb >> ?example(method) # Learn syntax
|
|
180
|
+
pretty_irb >> ?explain(map) # Specific method
|
|
181
|
+
pretty_irb >> ?example(array) # More examples
|
|
182
|
+
pretty_irb >> ?practices(readability) # Best practices
|
|
183
|
+
pretty_irb >> ?practices(performance) # Performance tips
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## 🎓 Topics Covered
|
|
189
|
+
|
|
190
|
+
### Methods (11 total)
|
|
191
|
+
map, select, each, reduce, find, merge, keys, values, gsub, split, join
|
|
192
|
+
|
|
193
|
+
### Examples (9 categories)
|
|
194
|
+
class, method, array, hash, string, loop, condition, error, block
|
|
195
|
+
|
|
196
|
+
### Best Practices (5 topics)
|
|
197
|
+
naming, performance, readability, testing, security
|
|
198
|
+
|
|
199
|
+
### References (4 types)
|
|
200
|
+
operators, symbols, variables, methods
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## 🚀 Getting Started
|
|
205
|
+
|
|
206
|
+
1. **Start Pretty IRB**
|
|
207
|
+
```bash
|
|
208
|
+
ruby bin/console
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
2. **Type help to see all commands**
|
|
212
|
+
```ruby
|
|
213
|
+
pretty_irb >> help
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
3. **Try your first AI command**
|
|
217
|
+
```ruby
|
|
218
|
+
pretty_irb >> ?explain(map)
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
4. **Start learning!**
|
|
222
|
+
```ruby
|
|
223
|
+
pretty_irb >> [1, 2, 3].map { |x| x * 2 }
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## 📖 Learn More
|
|
229
|
+
|
|
230
|
+
See [AI_HELP.md](AI_HELP.md) for complete documentation with all available methods, examples, and tips.
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
## ✅ Key Features
|
|
235
|
+
|
|
236
|
+
- ✅ **No Internet Needed** - All content built-in
|
|
237
|
+
- ✅ **Context Aware** - Stay in your REPL
|
|
238
|
+
- ✅ **Multiple Learning Styles** - Explanations, examples, references
|
|
239
|
+
- ✅ **Interactive** - Learn and practice together
|
|
240
|
+
- ✅ **Beginner Friendly** - Great for learning Ruby
|
|
241
|
+
- ✅ **Always Available** - Fast lookup
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
**Happy Learning!** 🎓
|
|
246
|
+
|
|
247
|
+
Start with: `?explain(map)` or `?example(class)`
|