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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1db19c9463f04b7e54357c0cdd3aaf2dc33e74f2d82f7ec4e6a1b949232c17f1
4
- data.tar.gz: e8fb0dd9ae7bb63ec86f043c646530d2614f8cbc04a2ef9a4566b58206eeb139
3
+ metadata.gz: 455620204255c774ac81923f080599183cda03da4990605ccdd516b17e60bfed
4
+ data.tar.gz: e1617267b3c9b240dd4a5115549ad2c333f054dee05eaa8408071126a4e37eab
5
5
  SHA512:
6
- metadata.gz: ffecda47f8fd505d5ae6adc071939668d77a248275554048f36300750f219660d7d876155a0767816f67d01abde2f9a308c5755e62a3fbe2a5e919667b27caa7
7
- data.tar.gz: 6906dbf9af719531f725f7fb5175166382626fda407712c46e7087414df09115a5768866e9df36eacf4389bca11959e8a5091127a58a629f7d9d009a0d1e470d
6
+ metadata.gz: 9842eb424f88442ff8915b15ebf1754ccb95a86643ada5619a750829d80ccb513e39f65f4b804fbb4d23f18439cd6c09f47d64fe7d2f01c069d459f2a70c685a
7
+ data.tar.gz: c6e859ae895a47df11eed8298e943b6b841f6412ae507a16ca852df235aaf8fc0f227752f3d68060d217945829aae5a329f9868b8dd15b1837a6ffc191f911b7
@@ -39,6 +39,7 @@ Gem::Specification.new do |spec|
39
39
  "lib/irb/color.rb",
40
40
  "lib/irb/completion.rb",
41
41
  "lib/irb/context.rb",
42
+ "lib/irb/easter-egg.rb",
42
43
  "lib/irb/ext/change-ws.rb",
43
44
  "lib/irb/ext/history.rb",
44
45
  "lib/irb/ext/loader.rb",
@@ -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
- conditions |= ReservedWords
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__
@@ -11,7 +11,7 @@
11
11
  #
12
12
 
13
13
  module IRB # :nodoc:
14
- VERSION = "1.2.2"
14
+ VERSION = "1.2.3"
15
15
  @RELEASE_VERSION = VERSION
16
- @LAST_UPDATE_DATE = "2020-02-14"
16
+ @LAST_UPDATE_DATE = "2020-02-15"
17
17
  end
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.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-14 00:00:00.000000000 Z
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