irb 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/irb.gemspec +1 -0
- data/lib/irb/completion.rb +3 -2
- data/lib/irb/easter-egg.rb +137 -0
- data/lib/irb/version.rb +2 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 455620204255c774ac81923f080599183cda03da4990605ccdd516b17e60bfed
|
4
|
+
data.tar.gz: e1617267b3c9b240dd4a5115549ad2c333f054dee05eaa8408071126a4e37eab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9842eb424f88442ff8915b15ebf1754ccb95a86643ada5619a750829d80ccb513e39f65f4b804fbb4d23f18439cd6c09f47d64fe7d2f01c069d459f2a70c685a
|
7
|
+
data.tar.gz: c6e859ae895a47df11eed8298e943b6b841f6412ae507a16ca852df235aaf8fc0f227752f3d68060d217945829aae5a329f9868b8dd15b1837a6ffc191f911b7
|
data/irb.gemspec
CHANGED
data/lib/irb/completion.rb
CHANGED
@@ -17,11 +17,12 @@ module IRB
|
|
17
17
|
# Set of reserved words used by Ruby, you should not use these for
|
18
18
|
# constants or variables
|
19
19
|
ReservedWords = %w[
|
20
|
+
__ENCODING__ __LINE__ __FILE__
|
20
21
|
BEGIN END
|
21
22
|
alias and
|
22
23
|
begin break
|
23
24
|
case class
|
24
|
-
def defined do
|
25
|
+
def defined? do
|
25
26
|
else elsif end ensure
|
26
27
|
false for
|
27
28
|
if in
|
@@ -255,7 +256,7 @@ module IRB
|
|
255
256
|
|
256
257
|
else
|
257
258
|
candidates = eval("methods | private_methods | local_variables | instance_variables | self.class.constants", bind).collect{|m| m.to_s}
|
258
|
-
|
259
|
+
candidates |= ReservedWords
|
259
260
|
|
260
261
|
if doc_namespace
|
261
262
|
candidates.find{ |i| i == input }
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require "reline"
|
2
|
+
|
3
|
+
module IRB
|
4
|
+
class << self
|
5
|
+
class Vec
|
6
|
+
def initialize(x, y, z)
|
7
|
+
@x, @y, @z = x, y, z
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_reader :x, :y, :z
|
11
|
+
|
12
|
+
def sub(other)
|
13
|
+
Vec.new(@x - other.x, @y - other.y, @z - other.z)
|
14
|
+
end
|
15
|
+
|
16
|
+
def dot(other)
|
17
|
+
@x*other.x + @y*other.y + @z*other.z
|
18
|
+
end
|
19
|
+
|
20
|
+
def cross(other)
|
21
|
+
ox, oy, oz = other.x, other.y, other.z
|
22
|
+
Vec.new(@y*oz-@z*oy, @z*ox-@x*oz, @x*oy-@y*ox)
|
23
|
+
end
|
24
|
+
|
25
|
+
def normalize
|
26
|
+
r = Math.sqrt(self.dot(self))
|
27
|
+
Vec.new(@x / r, @y / r, @z / r)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class Canvas
|
32
|
+
def initialize((h, w))
|
33
|
+
@data = (0..h-2).map { [0] * w }
|
34
|
+
@scale = [w / 2.0, h-2].min
|
35
|
+
@center = Complex(w / 2, h-2)
|
36
|
+
end
|
37
|
+
|
38
|
+
def line((x1, y1), (x2, y2))
|
39
|
+
p1 = Complex(x1, y1) / 2 * @scale + @center
|
40
|
+
p2 = Complex(x2, y2) / 2 * @scale + @center
|
41
|
+
line0(p1, p2)
|
42
|
+
end
|
43
|
+
|
44
|
+
private def line0(p1, p2)
|
45
|
+
mid = (p1 + p2) / 2
|
46
|
+
if (p1 - p2).abs < 1
|
47
|
+
x, y = mid.rect
|
48
|
+
@data[y / 2][x] |= (y % 2 > 1 ? 2 : 1)
|
49
|
+
else
|
50
|
+
line0(p1, mid)
|
51
|
+
line0(p2, mid)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def draw
|
56
|
+
@data.each {|row| row.fill(0) }
|
57
|
+
yield
|
58
|
+
@data.map {|row| row.map {|n| " ',;"[n] }.join }.join("\n")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class RubyModel
|
63
|
+
def initialize
|
64
|
+
@faces = init_ruby_model
|
65
|
+
end
|
66
|
+
|
67
|
+
def init_ruby_model
|
68
|
+
cap_vertices = (0..5).map {|i| Vec.new(*Complex.polar(1, i * Math::PI / 3).rect, 1) }
|
69
|
+
middle_vertices = (0..5).map {|i| Vec.new(*Complex.polar(2, (i + 0.5) * Math::PI / 3).rect, 0) }
|
70
|
+
bottom_vertex = Vec.new(0, 0, -2)
|
71
|
+
|
72
|
+
faces = [cap_vertices]
|
73
|
+
6.times do |j|
|
74
|
+
i = j-1
|
75
|
+
faces << [cap_vertices[i], middle_vertices[i], cap_vertices[j]]
|
76
|
+
faces << [cap_vertices[j], middle_vertices[i], middle_vertices[j]]
|
77
|
+
faces << [middle_vertices[i], bottom_vertex, middle_vertices[j]]
|
78
|
+
end
|
79
|
+
|
80
|
+
faces
|
81
|
+
end
|
82
|
+
|
83
|
+
def render_frame(i)
|
84
|
+
angle = i / 10.0
|
85
|
+
dir = Vec.new(*Complex.polar(1, angle).rect, Math.sin(angle)).normalize
|
86
|
+
dir2 = Vec.new(*Complex.polar(1, angle - Math::PI/2).rect, 0)
|
87
|
+
up = dir.cross(dir2)
|
88
|
+
nm = dir.cross(up)
|
89
|
+
@faces.each do |vertices|
|
90
|
+
v0, v1, v2, = vertices
|
91
|
+
if v1.sub(v0).cross(v2.sub(v0)).dot(dir) > 0
|
92
|
+
points = vertices.map {|p| [nm.dot(p), up.dot(p)] }
|
93
|
+
(points + [points[0]]).each_cons(2) do |p1, p2|
|
94
|
+
yield p1, p2
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
private def easter_egg(type = nil)
|
102
|
+
type ||= [:logo, :dancing].sample
|
103
|
+
case type
|
104
|
+
when :logo
|
105
|
+
File.open(File.join(__dir__, 'ruby_logo.aa')) do |f|
|
106
|
+
require "rdoc"
|
107
|
+
RDoc::RI::Driver.new.page do |io|
|
108
|
+
IO.copy_stream(f, io)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
when :dancing
|
112
|
+
begin
|
113
|
+
canvas = Canvas.new(Reline.get_screen_size)
|
114
|
+
Reline::IOGate.set_winch_handler do
|
115
|
+
canvas = Canvas.new(Reline.get_screen_size)
|
116
|
+
end
|
117
|
+
ruby_model = RubyModel.new
|
118
|
+
print "\e[?1049h"
|
119
|
+
0.step do |i| # TODO (0..).each needs Ruby 2.6 or later
|
120
|
+
buff = canvas.draw do
|
121
|
+
ruby_model.render_frame(i) do |p1, p2|
|
122
|
+
canvas.line(p1, p2)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
buff[0, 20] = "\e[0mPress Ctrl+C to stop\e[31m\e[1m"
|
126
|
+
print "\e[H" + buff
|
127
|
+
sleep 0.05
|
128
|
+
end
|
129
|
+
ensure
|
130
|
+
print "\e[0m\e[?1049l"
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
IRB.send(:easter_egg, ARGV[0]&.to_sym) if $0 == __FILE__
|
data/lib/irb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: irb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keiju ISHITSUKA
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-02-
|
11
|
+
date: 2020-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: reline
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- lib/irb/color.rb
|
83
83
|
- lib/irb/completion.rb
|
84
84
|
- lib/irb/context.rb
|
85
|
+
- lib/irb/easter-egg.rb
|
85
86
|
- lib/irb/ext/change-ws.rb
|
86
87
|
- lib/irb/ext/history.rb
|
87
88
|
- lib/irb/ext/loader.rb
|