Class: Girb::Tools::ListMethods
- Inherits:
-
Base
- Object
- Base
- Girb::Tools::ListMethods
show all
- Defined in:
- lib/girb/tools/list_methods.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
available?, to_gemini_tool, tool_name
Class Method Details
.description ⇒ Object
9
10
11
|
# File 'lib/girb/tools/list_methods.rb', line 9
def description
"List methods available on an object or class. Can filter by pattern."
end
|
.parameters ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/girb/tools/list_methods.rb', line 13
def parameters
{
type: "object",
properties: {
expression: {
type: "string",
description: "The variable name or expression to list methods for"
},
pattern: {
type: "string",
description: "Optional regex pattern to filter method names (e.g., 'valid', 'save')"
},
include_inherited: {
type: "boolean",
description: "Whether to include inherited methods (default: false)"
}
},
required: ["expression"]
}
end
|
Instance Method Details
#execute(binding, expression:, pattern: nil, include_inherited: false) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/girb/tools/list_methods.rb', line 35
def execute(binding, expression:, pattern: nil, include_inherited: false)
obj = binding.eval(expression)
methods = if obj.is_a?(Class) || obj.is_a?(Module)
{
instance_methods: obj.instance_methods(!include_inherited),
class_methods: obj.methods(!include_inherited)
}
else
{
methods: obj.methods(!include_inherited)
}
end
if pattern && !pattern.empty?
regex = Regexp.new(pattern, Regexp::IGNORECASE)
methods = methods.transform_values do |list|
list.select { |m| m.to_s.match?(regex) }
end
end
methods.transform_values(&:sort)
rescue RegexpError => e
{ error: "Invalid pattern: #{e.message}" }
rescue StandardError => e
{ error: "#{e.class}: #{e.message}" }
end
|