rhodes 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -0
- data/History.txt +4 -0
- data/Manifest.txt +52 -0
- data/README.rdoc +2 -0
- data/Rakefile +33 -0
- data/bin/rhogen +8 -0
- data/generators/rhogen.rb +99 -0
- data/generators/templates/application/application.rb +4 -0
- data/generators/templates/application/index.html +25 -0
- data/generators/templates/model/config.rb +3 -0
- data/generators/templates/model/controller.rb +48 -0
- data/generators/templates/model/edit.erb +21 -0
- data/generators/templates/model/index.erb +10 -0
- data/generators/templates/model/new.erb +16 -0
- data/lib/ServeME.rb +7 -0
- data/lib/TestServe.rb +9 -0
- data/lib/builtinME.rb +481 -0
- data/lib/date.rb +1781 -0
- data/lib/date/format.rb +1313 -0
- data/lib/erb.rb +896 -0
- data/lib/find.rb +81 -0
- data/lib/rational.rb +19 -0
- data/lib/rho.rb +1 -0
- data/lib/rho/render.rb +9 -0
- data/lib/rho/renderME.rb +8 -0
- data/lib/rho/rho.rb +173 -0
- data/lib/rho/rhoapplication.rb +36 -0
- data/lib/rho/rhocontroller.rb +51 -0
- data/lib/rho/rhofsconnector.rb +39 -0
- data/lib/rho/rhofsconnectorME.rb +36 -0
- data/lib/rho/rhosupport.rb +139 -0
- data/lib/rhodes.rb +5 -0
- data/lib/rhofsconnector.rb +5 -0
- data/lib/rhom.rb +1 -0
- data/lib/rhom/rhom.rb +41 -0
- data/lib/rhom/rhom_db_adapter.rb +183 -0
- data/lib/rhom/rhom_db_adapterME.rb +91 -0
- data/lib/rhom/rhom_object.rb +53 -0
- data/lib/rhom/rhom_object_factory.rb +246 -0
- data/lib/singleton.rb +313 -0
- data/lib/time.rb +839 -0
- data/rhodes.gemspec +18 -0
- data/spec/app_generator_spec.rb +27 -0
- data/spec/generator_spec_helper.rb +12 -0
- data/spec/model_generator_spec.rb +28 -0
- data/spec/rho_spec.rb +28 -0
- data/spec/rhom_object_factory_spec.rb +147 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/stubs.rb +17 -0
- data/spec/syncdbtest.sqlite +0 -0
- data/tasks/rspec.rake +34 -0
- metadata +157 -0
data/.gitignore
ADDED
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
.gitignore
|
2
|
+
History.txt
|
3
|
+
Manifest.txt
|
4
|
+
README.rdoc
|
5
|
+
Rakefile
|
6
|
+
bin/rhogen
|
7
|
+
generators/rhogen.rb
|
8
|
+
generators/templates/application/application.rb
|
9
|
+
generators/templates/application/index.html
|
10
|
+
generators/templates/model/config.rb
|
11
|
+
generators/templates/model/controller.rb
|
12
|
+
generators/templates/model/edit.erb
|
13
|
+
generators/templates/model/index.erb
|
14
|
+
generators/templates/model/new.erb
|
15
|
+
lib/ServeME.rb
|
16
|
+
lib/TestServe.rb
|
17
|
+
lib/builtinME.rb
|
18
|
+
lib/date.rb
|
19
|
+
lib/date/format.rb
|
20
|
+
lib/erb.rb
|
21
|
+
lib/find.rb
|
22
|
+
lib/rational.rb
|
23
|
+
lib/rho.rb
|
24
|
+
lib/rho/render.rb
|
25
|
+
lib/rho/renderME.rb
|
26
|
+
lib/rho/rho.rb
|
27
|
+
lib/rho/rhoapplication.rb
|
28
|
+
lib/rho/rhocontroller.rb
|
29
|
+
lib/rho/rhofsconnector.rb
|
30
|
+
lib/rho/rhofsconnectorME.rb
|
31
|
+
lib/rho/rhosupport.rb
|
32
|
+
lib/rhodes.rb
|
33
|
+
lib/rhofsconnector.rb
|
34
|
+
lib/rhom.rb
|
35
|
+
lib/rhom/rhom.rb
|
36
|
+
lib/rhom/rhom_db_adapter.rb
|
37
|
+
lib/rhom/rhom_db_adapterME.rb
|
38
|
+
lib/rhom/rhom_object.rb
|
39
|
+
lib/rhom/rhom_object_factory.rb
|
40
|
+
lib/singleton.rb
|
41
|
+
lib/time.rb
|
42
|
+
rhodes.gemspec
|
43
|
+
spec/app_generator_spec.rb
|
44
|
+
spec/generator_spec_helper.rb
|
45
|
+
spec/model_generator_spec.rb
|
46
|
+
spec/rho_spec.rb
|
47
|
+
spec/rhom_object_factory_spec.rb
|
48
|
+
spec/spec.opts
|
49
|
+
spec/spec_helper.rb
|
50
|
+
spec/stubs.rb
|
51
|
+
spec/syncdbtest.sqlite
|
52
|
+
tasks/rspec.rake
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
%w[rubygems rake rake/clean fileutils newgem].each { |f| require f }
|
2
|
+
$:.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
3
|
+
require 'rhodes'
|
4
|
+
|
5
|
+
task :default => [:spec, :features]
|
6
|
+
|
7
|
+
# Generate all the Rake tasks
|
8
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
9
|
+
$hoe = Hoe.new('rhodes', Rhodes::VERSION) do |p|
|
10
|
+
p.developer('Rhomobile Dev', 'dev@rhomobile.com')
|
11
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
12
|
+
#p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
13
|
+
p.rubyforge_name = p.name # TODO this is default value
|
14
|
+
p.extra_deps = [
|
15
|
+
['sqlite3-ruby','>= 1.2.4'],
|
16
|
+
['rcov'],
|
17
|
+
['rspec'],
|
18
|
+
]
|
19
|
+
p.extra_dev_deps = [
|
20
|
+
['newgem', ">= #{::Newgem::VERSION}"]
|
21
|
+
]
|
22
|
+
|
23
|
+
p.clean_globs |= %w[**/.DS_Store tmp *.log]
|
24
|
+
path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
|
25
|
+
p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
|
26
|
+
p.rsync_args = '-av --delete --ignore-errors'
|
27
|
+
p.test_globs = ''
|
28
|
+
end
|
29
|
+
|
30
|
+
require 'newgem/tasks' # load /tasks/*.rake
|
31
|
+
# remove test task TODO: why does this run anyway?
|
32
|
+
Rake.application.remove_task(:test)
|
33
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
data/bin/rhogen
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'templater'
|
3
|
+
|
4
|
+
module Rhogen
|
5
|
+
|
6
|
+
extend Templater::Manifold
|
7
|
+
|
8
|
+
desc <<-DESC
|
9
|
+
Generate rhodes application
|
10
|
+
DESC
|
11
|
+
|
12
|
+
class BaseGenerator < Templater::Generator
|
13
|
+
def class_name
|
14
|
+
name.gsub('-', '_').camel_case
|
15
|
+
end
|
16
|
+
|
17
|
+
alias_method :module_name, :class_name
|
18
|
+
end
|
19
|
+
|
20
|
+
class AppGenerator < BaseGenerator
|
21
|
+
|
22
|
+
def self.source_root
|
23
|
+
File.join(File.dirname(__FILE__), 'templates', 'application')
|
24
|
+
end
|
25
|
+
|
26
|
+
desc <<-DESC
|
27
|
+
Generates a new rhodes application. This will create a new directory with two files:
|
28
|
+
application.rb and index.html
|
29
|
+
DESC
|
30
|
+
|
31
|
+
#option :testing_framework, :desc => 'Specify which testing framework to use (spec, test_unit)'
|
32
|
+
|
33
|
+
first_argument :name, :required => true, :desc => "application name"
|
34
|
+
|
35
|
+
template :application do |template|
|
36
|
+
template.source = 'application.rb'
|
37
|
+
template.destination = "#{name}/application.rb"
|
38
|
+
end
|
39
|
+
|
40
|
+
template :index do |template|
|
41
|
+
template.source = 'index.html'
|
42
|
+
template.destination = "#{name}/index.html"
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
class ModelGenerator < BaseGenerator
|
48
|
+
|
49
|
+
def self.source_root
|
50
|
+
File.join(File.dirname(__FILE__), 'templates', 'model')
|
51
|
+
end
|
52
|
+
|
53
|
+
desc <<-DESC
|
54
|
+
Generates a new model for a given source. You must specify name, source_url, and source_id.
|
55
|
+
You can also specify an optional attribute list in the form: 'attribute1', 'attribute2', 'attribute3'...
|
56
|
+
DESC
|
57
|
+
|
58
|
+
#option :testing_framework, :desc => 'Specify which testing framework to use (spec, test_unit)'
|
59
|
+
|
60
|
+
first_argument :name, :required => true, :desc => "model name"
|
61
|
+
second_argument :source_url, :required => true, :desc => "source url"
|
62
|
+
third_argument :source_id, :required => true, :desc => "source id"
|
63
|
+
fourth_argument :attributes, :as => :array, :default => [], :required => false, :desc => "array of attributes (only string suppported right now)"
|
64
|
+
|
65
|
+
template :config do |template|
|
66
|
+
template.source = 'config.rb'
|
67
|
+
template.destination = "#{name.camel_case}/config.rb"
|
68
|
+
end
|
69
|
+
|
70
|
+
template :index do |template|
|
71
|
+
template.source = 'index.erb'
|
72
|
+
template.destination = "#{name.camel_case}/index.erb"
|
73
|
+
end
|
74
|
+
|
75
|
+
template :edit do |template|
|
76
|
+
template.source = 'edit.erb'
|
77
|
+
template.destination = "#{name.camel_case}/edit.erb"
|
78
|
+
end
|
79
|
+
|
80
|
+
template :new do |template|
|
81
|
+
template.source = 'new.erb'
|
82
|
+
template.destination = "#{name.camel_case}/new.erb"
|
83
|
+
end
|
84
|
+
|
85
|
+
template :controller do |template|
|
86
|
+
template.source = 'controller.rb'
|
87
|
+
template.destination = "#{name.camel_case}/controller.rb"
|
88
|
+
end
|
89
|
+
|
90
|
+
def attributes?
|
91
|
+
self.attributes && !self.attributes.empty?
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
add :app, AppGenerator
|
97
|
+
add :model, ModelGenerator
|
98
|
+
|
99
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
4
|
+
<head>
|
5
|
+
<title><%= class_name %></title>
|
6
|
+
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
|
7
|
+
<style type="text/css" media="screen">@import "/shared/js/iui/iui.css"; @import "/shared/css/rho.css";</style>
|
8
|
+
<script type="application/x-javascript" src="/shared/js/iui/iui.js"></script>
|
9
|
+
<script src="/shared/js/jquery-1.2.6.min.js"></script>
|
10
|
+
<script src="/shared/js/rho.js"></script>
|
11
|
+
</head>
|
12
|
+
<body>
|
13
|
+
<div class="toolbar">
|
14
|
+
<h1 id="pageTitle">
|
15
|
+
<script language="JavaScript">
|
16
|
+
document.write(document.title)
|
17
|
+
</script>
|
18
|
+
</h1>
|
19
|
+
<a id="backButton" class="button" href="./"></a>
|
20
|
+
</div>
|
21
|
+
<ul id="home" selected="true" title="<%= class_name %>">
|
22
|
+
<li>Something interesting here...</li>
|
23
|
+
</ul>
|
24
|
+
</body>
|
25
|
+
</html>
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'rho/rhocontroller'
|
2
|
+
|
3
|
+
class <%= class_name %>Controller < Rho::RhoController
|
4
|
+
|
5
|
+
#GET /<%= class_name %>
|
6
|
+
def index
|
7
|
+
@<%= name.pluralize %> = <%= class_name %>.find(:all)
|
8
|
+
render :index
|
9
|
+
end
|
10
|
+
|
11
|
+
# GET /<%= class_name %>/1
|
12
|
+
def show
|
13
|
+
@<%= name.pluralize %> = <%= class_name %>.find(@params['object'])
|
14
|
+
end
|
15
|
+
|
16
|
+
# GET /<%= class_name %>/new
|
17
|
+
def new
|
18
|
+
@<%= name %> = <%= class_name %>.new
|
19
|
+
render :new
|
20
|
+
end
|
21
|
+
|
22
|
+
# GET /<%= class_name %>/1/edit
|
23
|
+
def edit
|
24
|
+
@<%= name %> = <%= class_name %>.find(@params['id'])
|
25
|
+
render :edit
|
26
|
+
end
|
27
|
+
|
28
|
+
# POST /<%= class_name %>/create
|
29
|
+
def create
|
30
|
+
@<%= name %> = <%= class_name %>.new(@params['<%= name %>'])
|
31
|
+
@<%= name %>.save
|
32
|
+
redirect :index
|
33
|
+
end
|
34
|
+
|
35
|
+
# POST /<%= class_name %>/1/update
|
36
|
+
def update
|
37
|
+
@<%= name %> = <%= class_name %>.find(@params['id'])
|
38
|
+
@<%= name %>.update_attributes(@params['<%= name %>'])
|
39
|
+
redirect :index
|
40
|
+
end
|
41
|
+
|
42
|
+
# POST /<%= class_name %>/1/delete
|
43
|
+
def delete
|
44
|
+
@<%= name %> = <%= class_name %>.find(@params['id'])
|
45
|
+
@<%= name %>.destroy
|
46
|
+
redirect :index
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<form title="Edit <%= class_name %>"
|
2
|
+
class="panel"
|
3
|
+
id="<%= name %>_edit_form"
|
4
|
+
method="POST"
|
5
|
+
action="<%%=url_for('update')%>">
|
6
|
+
<fieldset>
|
7
|
+
<input type="hidden" name="id" value="<%%=@<%= name %>.object%>"/>
|
8
|
+
<% attributes.each do |attribute| %>
|
9
|
+
<div class="row">
|
10
|
+
<label><%=attribute%>: </label>
|
11
|
+
<input type="text" name="<%= name %>[<%= attribute %>]" value="<%%=@<%=name%>.<%=attribute%>%>"/>
|
12
|
+
</div>
|
13
|
+
<% end %>
|
14
|
+
</fieldset>
|
15
|
+
<input type="submit" value="Update"/>
|
16
|
+
<p align="center">
|
17
|
+
<a href="<%%=url_for('delete', @<%= name %>.object)%>">
|
18
|
+
<font color="#990000">Delete</font>
|
19
|
+
</a>
|
20
|
+
</p>
|
21
|
+
</form>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<ul id="<%= name.pluralize %>" title="<%= class_name.pluralize %>">
|
2
|
+
<%%@<%=name.pluralize%>.each do |x|%>
|
3
|
+
<%if self.attributes?%>
|
4
|
+
<li><%%=link_to "#{x.<%=attributes[0]%>}", "edit", x.object%></li>
|
5
|
+
<%else%>
|
6
|
+
<li>Some list entry...</li>
|
7
|
+
<%end%>
|
8
|
+
<%%end%>
|
9
|
+
<li><font color="blue"><%%=link_to "New <%= class_name %>", "new"%></font></li>
|
10
|
+
</ul>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<form title="New <%= class_name %>"
|
2
|
+
class="panel"
|
3
|
+
id="<%= name %>_new_form"
|
4
|
+
method="POST"
|
5
|
+
action="<%%=url_for('create')%>">
|
6
|
+
<fieldset>
|
7
|
+
<input type="hidden" name="id" value="<%%=@<%= name %>.object%>"/>
|
8
|
+
<% attributes.each do |attribute| %>
|
9
|
+
<div class="row">
|
10
|
+
<label><%=attribute%>: </label>
|
11
|
+
<input type="text" name="<%= name %>[<%= attribute %>]"/>
|
12
|
+
</div>
|
13
|
+
<% end %>
|
14
|
+
</fieldset>
|
15
|
+
<input type="submit" value="Create"/>
|
16
|
+
</form>
|
data/lib/ServeME.rb
ADDED
data/lib/TestServe.rb
ADDED
data/lib/builtinME.rb
ADDED
@@ -0,0 +1,481 @@
|
|
1
|
+
$" = []
|
2
|
+
$* = ARGV
|
3
|
+
$SAFE = 0
|
4
|
+
|
5
|
+
TRUE = true
|
6
|
+
FALSE = false
|
7
|
+
NIL = nil
|
8
|
+
|
9
|
+
RUBY_VERSION = "1.8.5"
|
10
|
+
VERSION = "1.8.5"
|
11
|
+
|
12
|
+
TOPLEVEL_BINDING = self
|
13
|
+
|
14
|
+
module Kernel
|
15
|
+
def nil?
|
16
|
+
false
|
17
|
+
end
|
18
|
+
|
19
|
+
def fork
|
20
|
+
raise NotImplementedError, "the fork() function is unimplemented on this machine"
|
21
|
+
end
|
22
|
+
|
23
|
+
def =~ x
|
24
|
+
false
|
25
|
+
end
|
26
|
+
|
27
|
+
def singleton_method_added symbol
|
28
|
+
end
|
29
|
+
|
30
|
+
def singleton_method_removed symbol
|
31
|
+
end
|
32
|
+
|
33
|
+
def singleton_method_undefined symbol
|
34
|
+
end
|
35
|
+
|
36
|
+
#private
|
37
|
+
def require(file_name)
|
38
|
+
return false if ($".include?(file_name) || $".include?(file_name + ".rb"))
|
39
|
+
|
40
|
+
load(file_name);
|
41
|
+
end
|
42
|
+
|
43
|
+
#private
|
44
|
+
def load(file_name)
|
45
|
+
if __load_with_reflection__(file_name)
|
46
|
+
return true
|
47
|
+
end
|
48
|
+
|
49
|
+
# $:.each do |path|
|
50
|
+
# return true if load_rb_file(path, file_name)
|
51
|
+
# end
|
52
|
+
|
53
|
+
raise LoadError, "no such file to load -- " + file_name
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
def method_added symbol
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class Object
|
62
|
+
def to_a
|
63
|
+
[self]
|
64
|
+
end
|
65
|
+
|
66
|
+
alias type :class
|
67
|
+
|
68
|
+
private
|
69
|
+
def initialize
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
module Enumerable
|
74
|
+
def each_with_index
|
75
|
+
i = 0;
|
76
|
+
each {|x| yield x, i; i = i + 1}
|
77
|
+
end
|
78
|
+
|
79
|
+
def inject(*args)
|
80
|
+
if args.size == 0 then
|
81
|
+
vals = to_a
|
82
|
+
memo = vals[0]
|
83
|
+
vals[1..vals.size-1].each {|obj| memo = yield(memo, obj)}
|
84
|
+
return memo
|
85
|
+
elsif args.size == 1 then
|
86
|
+
memo = args[0]
|
87
|
+
each {|obj| memo = yield(memo, obj)}
|
88
|
+
return memo
|
89
|
+
else
|
90
|
+
nil
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def collect
|
95
|
+
arr = []
|
96
|
+
each{|obj| arr << yield(obj)}
|
97
|
+
return arr
|
98
|
+
end
|
99
|
+
|
100
|
+
alias map :collect
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
class Array
|
105
|
+
alias size length
|
106
|
+
|
107
|
+
def join(sepString="")
|
108
|
+
return to_s if sepString.nil? || sepString == ""
|
109
|
+
|
110
|
+
result = ""
|
111
|
+
(length - 1).times do |index|
|
112
|
+
result += (self[index].to_s) + sepString
|
113
|
+
end
|
114
|
+
result += self[length - 1].to_s if length != 0
|
115
|
+
result
|
116
|
+
end
|
117
|
+
|
118
|
+
alias map! collect!
|
119
|
+
|
120
|
+
def inspect
|
121
|
+
str = "["
|
122
|
+
is_first = true
|
123
|
+
self.each() { |x|
|
124
|
+
if (!is_first)
|
125
|
+
str << ", "
|
126
|
+
end
|
127
|
+
is_first = false
|
128
|
+
str << x.inspect
|
129
|
+
}
|
130
|
+
str << "]"
|
131
|
+
end
|
132
|
+
alias to_s inspect
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
class Time
|
137
|
+
include Comparable
|
138
|
+
end
|
139
|
+
|
140
|
+
class Hash
|
141
|
+
def each
|
142
|
+
ks = keys
|
143
|
+
ks.each {|k| yield([k, self[k]])}
|
144
|
+
end
|
145
|
+
|
146
|
+
def each_key
|
147
|
+
ks = keys
|
148
|
+
ks.each {|k| yield(k)}
|
149
|
+
end
|
150
|
+
|
151
|
+
def each_value
|
152
|
+
vs = values
|
153
|
+
vs.each {|k| yield(k)}
|
154
|
+
end
|
155
|
+
|
156
|
+
def empty?
|
157
|
+
length == 0
|
158
|
+
end
|
159
|
+
|
160
|
+
alias each_pair each
|
161
|
+
|
162
|
+
def inspect
|
163
|
+
r = '{'
|
164
|
+
is_first = true
|
165
|
+
each_pair do |k, v|
|
166
|
+
if !is_first
|
167
|
+
r << ", "
|
168
|
+
end
|
169
|
+
is_first = false
|
170
|
+
r << k.inspect
|
171
|
+
r << '=>'
|
172
|
+
r << v.inspect
|
173
|
+
end
|
174
|
+
r << '}'
|
175
|
+
end
|
176
|
+
|
177
|
+
alias to_s inspect
|
178
|
+
|
179
|
+
def invert
|
180
|
+
h = {}
|
181
|
+
each {|k, v| h[v] = k}
|
182
|
+
h
|
183
|
+
end
|
184
|
+
|
185
|
+
def update other
|
186
|
+
other.each {|k, v| self[k] = v}
|
187
|
+
self
|
188
|
+
end
|
189
|
+
|
190
|
+
alias merge! update
|
191
|
+
|
192
|
+
def merge other
|
193
|
+
clone.merge!(other)
|
194
|
+
end
|
195
|
+
|
196
|
+
def index value
|
197
|
+
each {|k, v| return k if value == v }
|
198
|
+
return nil
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
class Symbol
|
203
|
+
alias to_s id2name
|
204
|
+
end
|
205
|
+
|
206
|
+
class << self
|
207
|
+
def to_s
|
208
|
+
return "main"
|
209
|
+
end
|
210
|
+
|
211
|
+
def public
|
212
|
+
Object.public
|
213
|
+
end
|
214
|
+
|
215
|
+
def private
|
216
|
+
Object.private
|
217
|
+
end
|
218
|
+
|
219
|
+
def protected
|
220
|
+
Object.protected
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
class Fixnum
|
225
|
+
def is_alpha_numeric
|
226
|
+
return (self>=?0 && self<=?9) || (self>=?a && self<=?z) || (self>=?A && self<=?Z)
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
module Comparable
|
231
|
+
def >=(value)
|
232
|
+
compare = (self <=> value)
|
233
|
+
return compare != -1 and compare != nil
|
234
|
+
end
|
235
|
+
|
236
|
+
def ==(value)
|
237
|
+
compare = (self <=> value)
|
238
|
+
return compare == 0
|
239
|
+
end
|
240
|
+
|
241
|
+
def <=(value)
|
242
|
+
compare = (self <=> value)
|
243
|
+
return compare != 1 and compare != nil
|
244
|
+
end
|
245
|
+
|
246
|
+
def >(value)
|
247
|
+
compare = (self <=> value)
|
248
|
+
return compare == 1
|
249
|
+
end
|
250
|
+
|
251
|
+
def <(value)
|
252
|
+
compare = (self <=> value)
|
253
|
+
return compare == -1
|
254
|
+
end
|
255
|
+
|
256
|
+
def between?(a, b)
|
257
|
+
self >= a && self <= b
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
class Numeric
|
262
|
+
include Comparable
|
263
|
+
|
264
|
+
def floor
|
265
|
+
self.to_f.floor
|
266
|
+
end
|
267
|
+
|
268
|
+
def abs
|
269
|
+
return -self if (self <=> 0) == -1
|
270
|
+
self
|
271
|
+
end
|
272
|
+
|
273
|
+
def div value
|
274
|
+
(self/value).floor
|
275
|
+
end
|
276
|
+
|
277
|
+
def divmod(value)
|
278
|
+
[(self/value).floor, self % value]
|
279
|
+
end
|
280
|
+
|
281
|
+
def integer?
|
282
|
+
false
|
283
|
+
end
|
284
|
+
|
285
|
+
alias eql? :==
|
286
|
+
|
287
|
+
def modulo(value)
|
288
|
+
self % value
|
289
|
+
end
|
290
|
+
|
291
|
+
def nonzero?
|
292
|
+
return nil if self == 0
|
293
|
+
self
|
294
|
+
end
|
295
|
+
|
296
|
+
def zero?
|
297
|
+
return true if self == 0
|
298
|
+
false
|
299
|
+
end
|
300
|
+
|
301
|
+
def remainder(value)
|
302
|
+
self_sign = (self < 0)
|
303
|
+
value_sign = (value < 0)
|
304
|
+
return self % value if self_sign == value_sign
|
305
|
+
self % (-value)
|
306
|
+
end
|
307
|
+
|
308
|
+
end
|
309
|
+
|
310
|
+
class Integer < Numeric
|
311
|
+
|
312
|
+
def to_i
|
313
|
+
return self
|
314
|
+
end
|
315
|
+
|
316
|
+
alias to_int to_i
|
317
|
+
|
318
|
+
#Returns the Integer equal to int + 1
|
319
|
+
def next
|
320
|
+
self + 1
|
321
|
+
end
|
322
|
+
|
323
|
+
#Synonym for Integer#next
|
324
|
+
def succ
|
325
|
+
self + 1
|
326
|
+
end
|
327
|
+
|
328
|
+
#Always returns true
|
329
|
+
def integer?
|
330
|
+
true
|
331
|
+
end
|
332
|
+
|
333
|
+
def upto(to)
|
334
|
+
a = self
|
335
|
+
while a <= to
|
336
|
+
yield a
|
337
|
+
a += 1
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
341
|
+
def downto(to)
|
342
|
+
a = self
|
343
|
+
while a >= to
|
344
|
+
yield a
|
345
|
+
a -= 1
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
349
|
+
def size
|
350
|
+
4
|
351
|
+
end
|
352
|
+
|
353
|
+
def integer?
|
354
|
+
true
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
class Fixnum < Integer
|
359
|
+
def to_i
|
360
|
+
self
|
361
|
+
end
|
362
|
+
|
363
|
+
alias inspect to_s
|
364
|
+
end
|
365
|
+
|
366
|
+
class NilClass
|
367
|
+
|
368
|
+
#Returns false
|
369
|
+
def &(anObject)
|
370
|
+
false
|
371
|
+
end
|
372
|
+
|
373
|
+
#Returns false if anObject is nil or false, true otherwise
|
374
|
+
def ^(anObject)
|
375
|
+
anObject ? true : false
|
376
|
+
end
|
377
|
+
|
378
|
+
#Returns false if anObject is nil or false, true otherwise
|
379
|
+
def |(anObject)
|
380
|
+
anObject ? true : false
|
381
|
+
end
|
382
|
+
|
383
|
+
#Always returns true
|
384
|
+
def nil?
|
385
|
+
true
|
386
|
+
end
|
387
|
+
|
388
|
+
#Always returns an empty array
|
389
|
+
def to_a
|
390
|
+
[]
|
391
|
+
end
|
392
|
+
|
393
|
+
#Always returns zero
|
394
|
+
def to_i
|
395
|
+
0
|
396
|
+
end
|
397
|
+
|
398
|
+
def to_f
|
399
|
+
0.0
|
400
|
+
end
|
401
|
+
|
402
|
+
#Always returns the empty string
|
403
|
+
def to_s
|
404
|
+
""
|
405
|
+
end
|
406
|
+
|
407
|
+
def inspect
|
408
|
+
"nil"
|
409
|
+
end
|
410
|
+
alias to_str to_s
|
411
|
+
end
|
412
|
+
|
413
|
+
class TrueClass
|
414
|
+
#Returns false if anObject is nil or false, true otherwise
|
415
|
+
def &(anObject)
|
416
|
+
anObject ? true : false
|
417
|
+
end
|
418
|
+
|
419
|
+
#Returns true if anObject is nil or false, false otherwise
|
420
|
+
def ^(anObject)
|
421
|
+
anObject ? false : true
|
422
|
+
end
|
423
|
+
|
424
|
+
#Returns true
|
425
|
+
def |(anObject)
|
426
|
+
true
|
427
|
+
end
|
428
|
+
|
429
|
+
def to_s
|
430
|
+
"true"
|
431
|
+
end
|
432
|
+
|
433
|
+
def inspect
|
434
|
+
"true"
|
435
|
+
end
|
436
|
+
end
|
437
|
+
|
438
|
+
class FalseClass
|
439
|
+
|
440
|
+
#Returns false
|
441
|
+
def &(anObject)
|
442
|
+
false
|
443
|
+
end
|
444
|
+
|
445
|
+
#If anObject is nil or false, returns false; otherwise, returns true
|
446
|
+
def ^(anObject)
|
447
|
+
anObject ? true : false
|
448
|
+
end
|
449
|
+
|
450
|
+
#Returns false if anObject is nil or false; true otherwise
|
451
|
+
def |(anObject)
|
452
|
+
anObject ? true : false
|
453
|
+
end
|
454
|
+
|
455
|
+
def to_s
|
456
|
+
"false"
|
457
|
+
end
|
458
|
+
|
459
|
+
def inspect
|
460
|
+
"false"
|
461
|
+
end
|
462
|
+
end
|
463
|
+
|
464
|
+
class String
|
465
|
+
include Comparable
|
466
|
+
|
467
|
+
def to_s
|
468
|
+
return self
|
469
|
+
end
|
470
|
+
|
471
|
+
def empty?
|
472
|
+
length == 0
|
473
|
+
end
|
474
|
+
|
475
|
+
def inspect
|
476
|
+
'"' + to_s + '"'
|
477
|
+
end
|
478
|
+
|
479
|
+
alias to_str to_s
|
480
|
+
alias size length
|
481
|
+
end
|