File: pen.rb

package info (click to toggle)
ruby-spy 1.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 360 kB
  • sloc: ruby: 3,101; makefile: 2
file content (87 lines) | stat: -rw-r--r-- 1,139 bytes parent folder | download
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
class Pen
  attr_reader :written, :color

  def initialize(color = :black)
    @color = color
    @written = []
  end

  def write(string)
    @written << string
    string
  end

  def write_block(&block)
    string = yield
    @written << string
    string
  end

  def write_hello
    write("hello")
  end

  def write_array(*args)
    args.each do |arg|
      write(arg)
    end
  end

  def greet(hello = "hello", name)
    write("#{hello} #{name}")
  end

  def public_method
  end

  def another
    "another"
  end

  def opt_kwargs(required, opt: nil, opt2: nil)
    [required, opt: opt, opt2: opt2]
  end

  def keyrest(**kwargs)
    kwargs
  end

  def req_kwargs(req1:, req2:)
    [req1, req2]
  end

  protected
  def protected_method
  end

  private
  def private_method
  end

  class << self
    def another
      "another"
    end

    def public_method
    end

    protected
    def protected_method
    end

    private
    def private_method
    end

  end
end

Pen.define_singleton_method(:meta_class_method) do
  "meta_class_method".freeze
end

Pen.send(:define_method, :meta_method) do
  "meta_method".freeze
end