This repository has been archived by the owner on Mar 26, 2023. It is now read-only.
/
Trac682.rb
82 lines (77 loc) · 2.05 KB
/
Trac682.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
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
# From DataMapper
#
# The class eval fails when the property_option is :format, but works ok
# when the property_option is :length
#
# The error is:
#
# $ mruby $pbm
# error , in class aMetaModule instVar format is private to Smalltalk,
# during /Users/pmclain/GemStone/dev/pbm.rb
# ERROR 2023, Error, ' in class aMetaModule instVar format is private to Smalltalk' (SyntaxError)
class Type
PROPERTY_OPTIONS = [:length, :format ]
class << self
PROPERTY_OPTIONS.each do |property_option|
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{property_option}(*args)
if args.any?
@#{property_option} = args.first
else
defined?(@#{property_option}) ? @#{property_option} : nil
end
end
RUBY
end
end
end
# Another instance from Rails:
class Railtie
class << self
def subclasses
@subclasses ||= []
end
end
end
#################### Trac Info
# ID: 682
# Summary: MagLev has trouble eval method def named 'format' - name clash with Smalltalk IV names
# Changetime: 2010-04-07 16:59:33+00:00
###
# From DataMapper:
#
# The eval of method def :length works, but the eval of method def :format fails (probably clash with Behavior>>format):
#
# {{{
#
# class Type
# PROPERTY_OPTIONS = [:length, :format ]
# class << self
# PROPERTY_OPTIONS.each do |property_option|
# self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
# def #{property_option}(*args)
# if args.any?
# @#{property_option} = args.first
# else
# defined?(@#{property_option}) ? @#{property_option} : nil
# end
# end
# RUBY
# end
# end
# end
#
# }}}
#
# The Error:
#
#
# {{{
# $ maglev-ruby src/test/TracXXX.rb
# error , in class aMetaModule instVar format is private to Smalltalk,
# during /Users/pmclain/GemStone/checkouts/git/src/test/TracXXX.rb
# ERROR 2023, Error, ' in class aMetaModule instVar format is private to Smalltalk' (SyntaxError)
#
# }}}
#
#