Class: PrettyIRB::AIHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/pretty_irb/ai_helper.rb

Class Method Summary collapse

Class Method Details

.best_practices(topic) ⇒ Object

Suggest best practices



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/pretty_irb/ai_helper.rb', line 74

def best_practices(topic)
  case topic.downcase
  when "naming"
    naming_conventions
  when "performance"
    performance_tips
  when "readability"
    readability_tips
  when "testing"
    testing_tips
  when "security"
    security_tips
  else
    general_best_practices
  end
end

.debug_code(code_snippet) ⇒ Object

Debug code snippet



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/pretty_irb/ai_helper.rb', line 57

def debug_code(code_snippet)
  analysis = {
    potential_issues: [],
    suggestions: [],
    complexity: analyze_complexity(code_snippet)
  }

  # Check for common issues

  analysis[:potential_issues] << "Missing error handling" if code_snippet.include?("begin") == false && has_risky_operations(code_snippet)
  analysis[:potential_issues] << "Potential nil reference" if code_snippet.include?(".") && !code_snippet.include?("&.")
  analysis[:suggestions] << "Consider using safe navigation operator (&.) for chained calls" if code_snippet.include?(".") && !code_snippet.include?("&.")
  analysis[:suggestions] << "Add error handling with begin/rescue/end" if analysis[:potential_issues].include?("Missing error handling")

  format_analysis(analysis)
end

.explain_method(method_name) ⇒ Object

Explain a Ruby method



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/pretty_irb/ai_helper.rb', line 5

def explain_method(method_name)
  case method_name.downcase
  when "map"
    explain_map
  when "select", "filter"
    explain_select
  when "each"
    explain_each
  when "reduce", "inject"
    explain_reduce
  when "find", "detect"
    explain_find
  when "merge"
    explain_merge
  when "keys", "values"
    explain_keys_values
  when "gsub", "sub"
    explain_gsub
  when "split", "join"
    explain_split_join
  else
    suggest_available_methods
  end
end

.get_example(concept) ⇒ Object

Get code example for a concept



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/pretty_irb/ai_helper.rb', line 31

def get_example(concept)
  case concept.downcase
  when "loop", "iteration"
    example_loops
  when "condition", "if"
    example_conditions
  when "class"
    example_class
  when "method"
    example_method
  when "array"
    example_array
  when "hash"
    example_hash
  when "string"
    example_string
  when "error", "exception"
    example_error_handling
  when "block", "proc"
    example_blocks
  else
    suggest_available_examples
  end
end

.quick_reference(keyword) ⇒ Object

Quick reference



92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/pretty_irb/ai_helper.rb', line 92

def quick_reference(keyword)
  case keyword.downcase
  when "operators"
    operators_reference
  when "symbols"
    symbols_reference
  when "variables"
    variables_reference
  when "methods"
    methods_reference
  else
    "Available references: operators, symbols, variables, methods"
  end
end