1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# frozen_string_literal: true
# A class demonstrating various method signatures.
# Method with no parameters.
#
# @return [String]
end
# Method with required parameters.
#
# @param first [String] the first value
# @param second [Integer] the second value
# @return [String]
end
# Method with optional parameters.
#
# @param value [String] the value
# @param prefix [String] optional prefix
# @param suffix [String] optional suffix
# @return [String]
end
# Method with keyword arguments.
#
# @param name [String] the name
# @param age [Integer] the age
# @param active [Boolean] whether active
# @return [Hash]
{ name: name, age: age, active: active }
end
# Method with splat parameters.
#
# @param items [Array<String>] variable number of items
# @return [Integer] the count
items.length
end
# Method with double splat (keyword splat).
#
# @param base [Hash] the base options
# @param options [Hash] additional options
# @return [Hash]
base.merge(options)
end
# Method with block parameter.
#
# @param items [Array] the items to process
# @yield [item] Yields each item
# @yieldparam item [Object] the current item
# @yieldreturn [Object] the transformed item
# @return [Array]
items.map(&block)
end
# Method that raises exceptions.
#
# @param value [Integer] the value to check
# @raise [ArgumentError] if value is negative
# @raise [RangeError] if value is too large
# @return [Integer]
raise ArgumentError, if value < 0
raise RangeError, if value > 100
value
end
protected
# A protected method.
#
# @return [void]
# implementation
end
private
# A private method.
#
# @return [void]
# implementation
end
end