-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdemo_data.rb
50 lines (42 loc) · 1.15 KB
/
demo_data.rb
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
#=========================================================================
#
# Name: demo_data.rb
#
# Purpose: Define a persistent class with public, private and protected
# instance methods, a class method, and some data we can explore
# using WebTools. Name it AAADemo so it will appear at the top
# of the Class list.
#
#=========================================================================
Maglev.persistent do
class AAADemo
# Provide easy access to PERSISTENT_ROOT
PROOT = Maglev::PERSISTENT_ROOT
def self.foo
"This is a class method"
end
def initialize
@foo = "foo"
@bar = "bar"
@rand = rand(100)
@a_hash = { :a => rand(51), :b => rand(72) }
end
protected
def protected_method
"This is a protected method"
end
private
def private_method
"This is a private method"
end
# Add a few constants
AN_INSTANCE = AAADemo.new
AN_ARRAY = []
30.times { |i| AN_ARRAY << i }
end
# Define a method programmatically
AAADemo.define_method(:metaprogrammed) do
x = :foo
"This method metaprogrammed to return #{x}"
end
end