goto 0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +19 -0
- data/lib/goto.rb +46 -0
- metadata +72 -0
data/README.textile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
h1. ruby-goto
|
2
|
+
|
3
|
+
ruby-goto, version -1.0, by Ryan Pavlik
|
4
|
+
|
5
|
+
'goto' for ruby. :-)
|
6
|
+
|
7
|
+
* Category: Library/Evil
|
8
|
+
* Status: squishy
|
9
|
+
* Created: 2003-06-06 05:06:14 GMT
|
10
|
+
|
11
|
+
h2. Description
|
12
|
+
|
13
|
+
This is a simple label-based goto for ruby. Just to show that it can be done.
|
14
|
+
|
15
|
+
Also to show that even though ruby may support certain features, even features that may be terribly abusable, does not mean that everyone will, in fact, terribly abuse them. ;-)
|
16
|
+
|
17
|
+
h2. License
|
18
|
+
|
19
|
+
GPL
|
data/lib/goto.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
STACK = []
|
2
|
+
|
3
|
+
class Label
|
4
|
+
attr_accessor :name;
|
5
|
+
attr_accessor :block;
|
6
|
+
|
7
|
+
def initialize(name, block);
|
8
|
+
@name = name
|
9
|
+
@block = block
|
10
|
+
end
|
11
|
+
|
12
|
+
def ==(sym)
|
13
|
+
@name == sym
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Goto < Exception;
|
18
|
+
attr_accessor :label
|
19
|
+
def initialize(label); @label = label; end
|
20
|
+
end
|
21
|
+
|
22
|
+
def label(sym, &block)
|
23
|
+
STACK.last << Label.new(sym, block)
|
24
|
+
end
|
25
|
+
|
26
|
+
def frame_start
|
27
|
+
STACK << []
|
28
|
+
end
|
29
|
+
|
30
|
+
def frame_end
|
31
|
+
frame = STACK.pop
|
32
|
+
idx = 0
|
33
|
+
|
34
|
+
begin
|
35
|
+
for i in (idx...frame.size)
|
36
|
+
frame[i].block.call if frame[i].block
|
37
|
+
end
|
38
|
+
rescue Goto => g
|
39
|
+
idx = frame.index(g.label)
|
40
|
+
retry
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def goto(label)
|
45
|
+
raise Goto.new(label)
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: goto
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
version: "0"
|
8
|
+
platform: ruby
|
9
|
+
authors:
|
10
|
+
- Benjamin Bock
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
|
15
|
+
date: 2010-02-23 00:00:00 +01:00
|
16
|
+
default_executable:
|
17
|
+
dependencies: []
|
18
|
+
|
19
|
+
description: |
|
20
|
+
==== Goto for Ruby
|
21
|
+
This is a simple label-based goto for ruby. Just to show that it can be done.
|
22
|
+
|
23
|
+
Also to show that even though ruby may support certain features, even features that may be terribly abusable, does not mean that everyone will, in fact, terribly abuse them. ;-)
|
24
|
+
|
25
|
+
==== Facts
|
26
|
+
* Category: Library/Evil
|
27
|
+
* Status: squishy
|
28
|
+
* Created: 2003-06-06 05:06:14 GMT
|
29
|
+
* Creator: Ryan Pavlik
|
30
|
+
|
31
|
+
email: bb--goto-gem@bock.be
|
32
|
+
executables: []
|
33
|
+
|
34
|
+
extensions: []
|
35
|
+
|
36
|
+
extra_rdoc_files: []
|
37
|
+
|
38
|
+
files:
|
39
|
+
- README.textile
|
40
|
+
- lib/goto.rb
|
41
|
+
has_rdoc: true
|
42
|
+
homepage: http://github.com/bb/ruby-goto
|
43
|
+
licenses: []
|
44
|
+
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.3.6
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: goto for ruby
|
71
|
+
test_files: []
|
72
|
+
|