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.
@@ -0,0 +1,440 @@
1
+ # Pretty IRB - Advanced Features Guide
2
+
3
+ ## 📜 History Manager
4
+
5
+ The History Manager keeps track of all commands you execute and provides powerful search and replay capabilities.
6
+
7
+ ### Commands
8
+
9
+ #### View History
10
+ ```ruby
11
+ history # Show all command history
12
+ history last 5 # Show last 5 commands
13
+ history search map # Search history for "map"
14
+ history export file.rb # Export history to file
15
+ history clear # Clear all history
16
+ ```
17
+
18
+ ### Examples
19
+
20
+ ```ruby
21
+ # Execute some code
22
+ [1, 2, 3].map { |x| x * 2 }
23
+ => [2, 4, 6]
24
+
25
+ # Search history for previous commands
26
+ history search map
27
+ # Output: Found 1 match:
28
+ # 1: [1, 2, 3].map { |x| x * 2 }
29
+ # Time: 14:32:45
30
+
31
+ # Get last 3 commands
32
+ history last 3
33
+
34
+ # Export for reference
35
+ history export my_session.rb
36
+ ```
37
+
38
+ ---
39
+
40
+ ## 💾 Snippet Manager
41
+
42
+ Save and reuse code snippets with tags and descriptions.
43
+
44
+ ### Commands
45
+
46
+ ```ruby
47
+ snippet list # List all saved snippets
48
+ snippet save NAME "CODE" # Save a code snippet
49
+ snippet load NAME # Load and execute snippet
50
+ snippet show NAME # Show snippet details
51
+ snippet delete NAME # Delete snippet
52
+ snippet search KEYWORD # Search snippets by keyword
53
+ ```
54
+
55
+ ### Examples
56
+
57
+ ```ruby
58
+ # Save a useful snippet
59
+ snippet save array_helpers "def double_array(arr); arr.map { |x| x * 2 }; end"
60
+ # Output: ✓ Snippet 'array_helpers' saved
61
+
62
+ # Load and use it later
63
+ snippet load array_helpers
64
+ # Output: 📌 Loaded snippet: array_helpers
65
+ # def double_array(arr); arr.map { |x| x * 2 }; end
66
+ # => :double_array
67
+
68
+ # Show all details
69
+ snippet show array_helpers
70
+ # Output: 📌 array_helpers
71
+ # Description:
72
+ # Created: 2025-11-26 14:35:22 +0000
73
+ # Tags: method, array
74
+ # Code:
75
+ # def double_array(arr); arr.map { |x| x * 2 }; end
76
+
77
+ # Search for snippets
78
+ snippet search array
79
+
80
+ # Delete when done
81
+ snippet delete array_helpers
82
+ ```
83
+
84
+ **Features:**
85
+ - Automatic tag detection (class, method, loop, string, array, hash, error-handling)
86
+ - JSON-based storage in `~/.pretty_irb_snippets/`
87
+ - Search by name, code content, or tags
88
+ - Description support for documentation
89
+
90
+ ---
91
+
92
+ ## 🔍 Variable Inspector
93
+
94
+ Inspect, search, and analyze all variables in your current REPL session.
95
+
96
+ ### Commands
97
+
98
+ ```ruby
99
+ vars # List all variables
100
+ vars VARNAME # Inspect specific variable
101
+ vars type:String # Find all String variables
102
+ vars type:Array # Find all Array variables
103
+ vars search:pattern # Search variable names
104
+ vars memory # Memory usage report
105
+ ```
106
+
107
+ ### Examples
108
+
109
+ ```ruby
110
+ # Create some variables
111
+ name = "Ruby"
112
+ numbers = [1, 2, 3, 4, 5]
113
+ config = {host: "localhost", port: 3000}
114
+
115
+ # List all variables
116
+ vars
117
+ # Output: 📦 Local Variables (3):
118
+ # name: String (5 bytes)
119
+ # = "Ruby"
120
+ # numbers: Array (40 bytes)
121
+ # = [1, 2, 3, 4, 5]
122
+ # config: Hash (80 bytes)
123
+ # = {:host=>"localhost", :port=>3000}
124
+
125
+ # Inspect specific variable
126
+ vars name
127
+ # Output: 📦 Variable: name
128
+ # Type: String
129
+ # Size: ~5 bytes
130
+ # Value: "Ruby"
131
+ # String Info:
132
+ # Length: 4
133
+ # Encoding: UTF-8
134
+
135
+ # Find all String variables
136
+ vars type:String
137
+ # Output: 📦 Variables of type String (1):
138
+ # name: String (5 bytes)
139
+ # = "Ruby"
140
+
141
+ # Memory usage
142
+ vars memory
143
+ # Output: 💾 Memory Usage:
144
+ # Total: ~0 KB
145
+ # name: ~5 bytes
146
+ # numbers: ~40 bytes
147
+ # config: ~80 bytes
148
+ ```
149
+
150
+ **Features:**
151
+ - Detailed variable inspection
152
+ - Type-based filtering
153
+ - Keyword search
154
+ - Memory usage estimation
155
+ - Shows first/last for collections
156
+ - Encoding info for strings
157
+ - Even/odd detection for numbers
158
+
159
+ ---
160
+
161
+ ## ⚡ Benchmarker
162
+
163
+ Measure code performance and compare implementations.
164
+
165
+ ### Commands
166
+
167
+ ```ruby
168
+ bench CODE # Benchmark code (1000 iterations)
169
+ bench compare CODE1 vs CODE2 # Compare two snippets
170
+ bench memory CODE # Profile memory allocation
171
+ ```
172
+
173
+ ### Examples
174
+
175
+ ```ruby
176
+ # Benchmark array creation
177
+ bench "[1, 2, 3, 4, 5] * 100"
178
+ # Output: ⏱️ Benchmark Results:
179
+ # Code: [1, 2, 3, 4, 5] * 100
180
+ # Iterations: 1000
181
+ # Total Time: 23.45 ms
182
+ # Per Iteration: 23.45 µs
183
+ # Rate: 42625 ops/sec
184
+
185
+ # Compare map vs each_with_object
186
+ bench compare "(1..100).map { |x| x * 2 }" vs "(1..100).each_with_object([]) { |x, arr| arr << x * 2 }"
187
+ # Output: ⚡ Comparison Results:
188
+ # Iterations: 1000
189
+ # Code 1 ((1..100).map { |x| x * 2 }):
190
+ # Time: 34.56 ms
191
+ # Code 2 ((1..100).each_with_object([]) { |x, ar):
192
+ # Time: 45.67 ms
193
+ # Winner: Code 1 is 24.5% faster
194
+
195
+ # Profile memory usage
196
+ bench memory "[1, 2, 3, 4, 5] * 1000"
197
+ # Output: 💾 Memory Profile:
198
+ # Iterations: 100
199
+ # Objects Allocated: 500
200
+ # Objects Freed: 450
201
+ # Net Objects: 50
202
+ # Per Iteration: 0.5 objects
203
+ ```
204
+
205
+ **Features:**
206
+ - Configurable iterations
207
+ - Real time measurements in milliseconds
208
+ - Per-iteration metrics
209
+ - Operations per second rate
210
+ - Comparison mode with winner calculation
211
+ - Memory profiling with GC statistics
212
+
213
+ ---
214
+
215
+ ## 📖 Ruby Cheat Sheet
216
+
217
+ Quick reference for Ruby syntax and methods.
218
+
219
+ ### Commands
220
+
221
+ ```ruby
222
+ cheat # Show general cheat sheet
223
+ cheat array # Array methods cheat sheet
224
+ cheat hash # Hash methods cheat sheet
225
+ cheat string # String methods cheat sheet
226
+ cheat enumerable # Enumerable methods cheat sheet
227
+ cheat file # File I/O operations
228
+ cheat regex # Regular expressions
229
+ cheat date # Date & Time operations
230
+ ```
231
+
232
+ ### Topics Covered
233
+
234
+ **General:**
235
+ - Variables & Constants
236
+ - Conditionals (if/unless/case)
237
+ - Loops (while/until/for/each)
238
+ - Methods & Classes
239
+ - Operators
240
+ - String/Array/Hash methods
241
+
242
+ **Array Cheat Sheet:**
243
+ - Creating arrays
244
+ - Accessing elements
245
+ - Modifying arrays
246
+ - Querying arrays
247
+ - Iteration methods
248
+ - Combining arrays
249
+ - Sorting
250
+
251
+ **Hash Cheat Sheet:**
252
+ - Creating hashes
253
+ - Accessing/adding values
254
+ - Removing values
255
+ - Querying hashes
256
+ - Iteration methods
257
+ - Transforming hashes
258
+
259
+ **String Cheat Sheet:**
260
+ - Creating strings
261
+ - Interpolation
262
+ - Case methods
263
+ - Querying strings
264
+ - Extracting substrings
265
+ - Searching & replacing
266
+ - Whitespace handling
267
+ - Conversion methods
268
+ - Formatting methods
269
+
270
+ **Enumerable Cheat Sheet:**
271
+ - Iteration (each, map, select)
272
+ - Reduction (reduce)
273
+ - Checking (any?, all?, none?)
274
+ - Grouping methods
275
+ - Sorting methods
276
+ - Other utilities
277
+
278
+ **File I/O Cheat Sheet:**
279
+ - Reading files
280
+ - Writing files
281
+ - Appending
282
+ - File checking
283
+ - Path operations
284
+ - File operations
285
+
286
+ **Regex Cheat Sheet:**
287
+ - Matching patterns
288
+ - Anchors
289
+ - Character classes
290
+ - Quantifiers
291
+ - Groups
292
+ - Flags
293
+ - Common patterns
294
+
295
+ **Date & Time Cheat Sheet:**
296
+ - Getting current time
297
+ - Creating dates
298
+ - Formatting
299
+ - Extracting components
300
+ - Arithmetic
301
+ - Comparing
302
+ - Conversion
303
+
304
+ ### Examples
305
+
306
+ ```ruby
307
+ # Get general overview
308
+ cheat
309
+ # Shows all basic Ruby syntax
310
+
311
+ # Quick reference for arrays
312
+ cheat array
313
+ # Shows all array methods with examples
314
+
315
+ # Reference for string manipulation
316
+ cheat string
317
+ # Shows string methods and examples
318
+
319
+ # Learn about regex
320
+ cheat regex
321
+ # Patterns and matching examples
322
+ ```
323
+
324
+ ---
325
+
326
+ ## 🎯 Integration with AI Helper
327
+
328
+ All new features work seamlessly with the AI Helper:
329
+
330
+ ```ruby
331
+ # Explain a method you found in cheatsheet
332
+ ?explain(map)
333
+
334
+ # Get example of array processing
335
+ ?example(array)
336
+
337
+ # Debug code before benchmarking
338
+ ?debug("arr.map { |x| x / 0 }")
339
+
340
+ # Learn best practices for performance
341
+ ?practices(performance)
342
+
343
+ # Quick reference for operators
344
+ ?ref(operators)
345
+ ```
346
+
347
+ ---
348
+
349
+ ## 💡 Pro Tips
350
+
351
+ 1. **Save Common Patterns**: Use snippets to save frequently used code blocks
352
+ 2. **Compare Implementations**: Use benchmarker to find the fastest solution
353
+ 3. **Track History**: Export history for reference or sharing
354
+ 4. **Inspect Variables**: Use `vars` to understand your current state
355
+ 5. **Learn as You Go**: Use cheatsheet as quick reference without leaving REPL
356
+
357
+ ---
358
+
359
+ ## 📊 Advanced Usage Examples
360
+
361
+ ### Performance Optimization Workflow
362
+
363
+ ```ruby
364
+ # 1. Load a snippet
365
+ snippet load expensive_algorithm
366
+
367
+ # 2. Benchmark current implementation
368
+ bench my_function([1,2,3,4,5])
369
+
370
+ # 3. Try optimized version
371
+ snippet save optimized_v1 "def fast_function(arr); arr.map { |x| x * 2 }; end"
372
+
373
+ # 4. Compare
374
+ bench compare my_function([1,2,3,4,5]) vs fast_function([1,2,3,4,5])
375
+
376
+ # 5. Analyze memory
377
+ bench memory my_function([1,2,3,4,5])
378
+
379
+ # 6. Check variables
380
+ vars memory
381
+
382
+ # 7. Export session
383
+ history export optimization_session.rb
384
+ ```
385
+
386
+ ### Learning Workflow
387
+
388
+ ```ruby
389
+ # 1. View cheatsheet for topic
390
+ cheat array
391
+
392
+ # 2. Try code from cheatsheet
393
+ [1, 2, 3].map { |x| x * 2 }
394
+
395
+ # 3. Get detailed explanation
396
+ ?explain(map)
397
+
398
+ # 4. See advanced example
399
+ ?example(array)
400
+
401
+ # 5. Learn best practices
402
+ ?practices(readability)
403
+
404
+ # 6. Benchmark different approaches
405
+ bench compare "[1,2,3].map { |x| x*2 }" vs "[1,2,3].collect { |x| x*2 }"
406
+
407
+ # 7. Save good patterns
408
+ snippet save array_doubling "[1,2,3].map { |x| x*2 }"
409
+ ```
410
+
411
+ ### Debugging Workflow
412
+
413
+ ```ruby
414
+ # 1. Write code that might fail
415
+ code = "result = 10 / 0"
416
+
417
+ # 2. Analyze with AI helper
418
+ ?debug(code)
419
+
420
+ # 3. Save working version
421
+ snippet save safe_division "result = 10 / 2 rescue 'Division by zero'"
422
+
423
+ # 4. Load and test
424
+ snippet load safe_division
425
+
426
+ # 5. Inspect resulting variables
427
+ vars result
428
+
429
+ # 6. View history of attempts
430
+ history search division
431
+ ```
432
+
433
+ ---
434
+
435
+ ## 📁 File Storage
436
+
437
+ - **Snippets**: `~/.pretty_irb_snippets/` (JSON format)
438
+ - **History Exports**: Anywhere you specify
439
+
440
+ All files are human-readable for easy sharing and version control.