summaryrefslogtreecommitdiff
path: root/sample
diff options
context:
space:
mode:
Diffstat (limited to 'sample')
-rw-r--r--sample/all-ruby-quine.rb24
-rw-r--r--sample/coverage.rb2
-rw-r--r--sample/dir.rb11
-rw-r--r--sample/drb/README.ja.rdoc59
-rw-r--r--sample/drb/README.rdoc56
-rw-r--r--sample/drb/acl.rb15
-rw-r--r--sample/drb/darray.rb12
-rw-r--r--sample/drb/darrayc.rb47
-rw-r--r--sample/drb/dbiff.rb51
-rw-r--r--sample/drb/dcdbiff.rb43
-rw-r--r--sample/drb/dchatc.rb41
-rw-r--r--sample/drb/dchats.rb69
-rw-r--r--sample/drb/dhasen.rb41
-rw-r--r--sample/drb/dhasenc.rb14
-rw-r--r--sample/drb/dlogc.rb16
-rw-r--r--sample/drb/dlogd.rb38
-rw-r--r--sample/drb/dqin.rb13
-rw-r--r--sample/drb/dqlib.rb14
-rw-r--r--sample/drb/dqout.rb14
-rw-r--r--sample/drb/dqueue.rb11
-rw-r--r--sample/drb/drbc.rb45
-rw-r--r--sample/drb/drbch.rb48
-rw-r--r--sample/drb/drbm.rb60
-rw-r--r--sample/drb/drbmc.rb22
-rw-r--r--sample/drb/drbs-acl.rb51
-rw-r--r--sample/drb/drbs.rb64
-rw-r--r--sample/drb/drbssl_c.rb19
-rw-r--r--sample/drb/drbssl_s.rb31
-rw-r--r--sample/drb/extserv_test.rb80
-rw-r--r--sample/drb/gw_ct.rb29
-rw-r--r--sample/drb/gw_cu.rb28
-rw-r--r--sample/drb/gw_s.rb10
-rw-r--r--sample/drb/holderc.rb22
-rw-r--r--sample/drb/holders.rb63
-rw-r--r--sample/drb/http0.rb77
-rw-r--r--sample/drb/http0serv.rb120
-rw-r--r--sample/drb/name.rb117
-rw-r--r--sample/drb/namec.rb36
-rw-r--r--sample/drb/old_tuplespace.rb212
-rw-r--r--sample/drb/rinda_ts.rb7
-rw-r--r--sample/drb/rindac.rb17
-rw-r--r--sample/drb/rindas.rb18
-rw-r--r--sample/drb/ring_echo.rb29
-rw-r--r--sample/drb/ring_inspect.rb30
-rw-r--r--sample/drb/ring_place.rb25
-rw-r--r--sample/drb/simpletuple.rb89
-rw-r--r--sample/drb/speedc.rb21
-rw-r--r--sample/drb/speeds.rb31
-rw-r--r--sample/exyacc.rb2
-rw-r--r--sample/from.rb2
-rwxr-xr-xsample/mine.rb8
-rw-r--r--sample/mpart.rb44
-rw-r--r--sample/net-imap.rb167
-rw-r--r--sample/openssl/c_rehash.rb2
-rw-r--r--sample/prism/find_calls.rb105
-rw-r--r--sample/prism/find_comments.rb100
-rw-r--r--sample/prism/locate_nodes.rb84
-rw-r--r--sample/prism/make_tags.rb302
-rw-r--r--sample/prism/multiplex_constants.rb138
-rw-r--r--sample/prism/relocate_constants.rb43
-rw-r--r--sample/prism/visit_nodes.rb63
-rw-r--r--sample/trick2015/kinaba/entry.rb4
-rw-r--r--sample/trick2018/02-mame/entry.rb4
-rw-r--r--sample/trick2022/01-tompng/Gemfile2
-rw-r--r--sample/trick2022/01-tompng/Gemfile.lock13
-rw-r--r--sample/trick2022/01-tompng/authors.markdown3
-rw-r--r--sample/trick2022/01-tompng/entry.rb40
-rw-r--r--sample/trick2022/01-tompng/remarks.markdown51
-rw-r--r--sample/trick2022/02-tompng/authors.markdown3
-rw-r--r--sample/trick2022/02-tompng/entry.rb32
-rw-r--r--sample/trick2022/02-tompng/remarks.markdown32
-rw-r--r--sample/trick2022/03-mame/authors.markdown3
-rw-r--r--sample/trick2022/03-mame/entry.rb27
-rw-r--r--sample/trick2022/03-mame/remarks.markdown96
-rw-r--r--sample/trick2022/03-mame/test.txt13
-rw-r--r--sample/trick2022/README.md14
-rw-r--r--sample/trick2025/01-omoikane/authors.markdown5
-rw-r--r--sample/trick2025/01-omoikane/bf.rb81
-rw-r--r--sample/trick2025/01-omoikane/entry.rb32
-rw-r--r--sample/trick2025/01-omoikane/remarks.markdown71
-rw-r--r--sample/trick2025/01-omoikane/sample_input.txt35
-rw-r--r--sample/trick2025/01-omoikane/spoiler_rot13.txt470
-rw-r--r--sample/trick2025/02-mame/authors.markdown3
-rw-r--r--sample/trick2025/02-mame/entry.rb34
-rw-r--r--sample/trick2025/02-mame/remarks.markdown141
-rw-r--r--sample/trick2025/02-mame/sample.orig.rb8
-rw-r--r--sample/trick2025/02-mame/test.patch16
-rw-r--r--sample/trick2025/03-tompng/authors.markdown3
-rw-r--r--sample/trick2025/03-tompng/entry.rb74
-rw-r--r--sample/trick2025/03-tompng/remarks.markdown146
-rw-r--r--sample/trick2025/04-tompng/authors.markdown3
-rw-r--r--sample/trick2025/04-tompng/entry.rb36
-rw-r--r--sample/trick2025/04-tompng/remarks.markdown43
-rw-r--r--sample/trick2025/05-tompng/authors.markdown3
-rw-r--r--sample/trick2025/05-tompng/entry.rb118
-rw-r--r--sample/trick2025/05-tompng/remarks.markdown106
-rw-r--r--sample/trick2025/README.md16
-rw-r--r--sample/uumerge.rb2
98 files changed, 2675 insertions, 2160 deletions
diff --git a/sample/all-ruby-quine.rb b/sample/all-ruby-quine.rb
new file mode 100644
index 0000000000..7686121468
--- /dev/null
+++ b/sample/all-ruby-quine.rb
@@ -0,0 +1,24 @@
+ eval($s=("t='eval($s=('+d=34.chr;s=3
+ 2.chr+$s*i=8;v=$VERSION||eval('begin;v=V
+ ERSION;rescue;v||RUBY_VERSION;end');f=('?'*8
+ +'A|'+'?'*20+'G?c'+'?'*15+'A@CXx@~@_`OpGxCxp@~pO
+ xS|O~G?c?q?xC`AP|q?x_|C_xC_xO@H@cG?G?qA|_|_`GCpOxC|H
+NFccqq@`_|OF@`?q?x_@x_x_`GB`O``O~G?C@qCxCxP@D@|G~C?pO|C?
+ pO|C?AP|A~HNN`ccxC|Q@L@B"+"GpGpc@p?x_`GB`???_@FO|OB@
+ xC|P`@?c?q?HPx@~@_`G@`????@L^`?q?x?xq@|_|O~GC`
+ xA~@_@GBD').unpack('c*');w=4+v.length*u=
+ 15;r=10.chr;j=0;while-24+w*u>i=1+i
+ ;x=i%w;x>0||t=t+d+'+'+r+d;k=
+ i/w%12>2&&x%u>3&&x%u+i
+ /w*11-34+('-._'.
+ index(c=v[
+ x/u,1]
+ )||c.hex +3)*99|
+ |0; k=f [k/6 ][k%
+ 6]; t=t +s[
+ k*j =k+ j,1
+ ]end;pr int (t+
+ d+' ).s pli
+ t.j oin [0,
+ 609 ])# Y.E. '+r)
+ ").split .join)#
diff --git a/sample/coverage.rb b/sample/coverage.rb
index 8e8d6167e2..42ba89fd50 100644
--- a/sample/coverage.rb
+++ b/sample/coverage.rb
@@ -49,7 +49,7 @@ at_exit do
end
end
- open(cfile, "w") do |out|
+ File.open(cfile, "w") do |out|
covs.zip(sources, pcovs).each_with_index do |(cov, line, pcov), idx|
cov += pcov || 0 if cov
cov = (cov ? (cov == 0 ? "#####" : cov.to_s) : "-").rjust(9)
diff --git a/sample/dir.rb b/sample/dir.rb
index 0c55078973..81257cd917 100644
--- a/sample/dir.rb
+++ b/sample/dir.rb
@@ -1,12 +1,7 @@
# directory access
# list all files but .*/*~/*.o
-dirp = Dir.open(".")
-for f in dirp
- case f
- when /\A\./, /~\z/, /\.o\z/
- # do not print
- else
- print f, "\n"
+Dir.foreach(".") do |file|
+ unless file.start_with?('.') or file.end_with?('~', '.o')
+ puts file
end
end
-dirp.close
diff --git a/sample/drb/README.ja.rdoc b/sample/drb/README.ja.rdoc
deleted file mode 100644
index 3ab70f3369..0000000000
--- a/sample/drb/README.ja.rdoc
+++ /dev/null
@@ -1,59 +0,0 @@
-= サンプルスクリプト
-
-* Arrayをリモートから利用してイテレータを試す。
- * darray.rb --- server
- * darrayc.rb --- client
-
-* 簡易チャット
- * dchats.rb --- server
- * dchatc.rb --- client
-
-* 分散chasen
- * dhasen.rb --- server
- * dhasenc.rb --- client
-
-* 簡易ログサーバ
- * dlogd.rb --- server
- * dlogc.rb --- client
-
-* Queueサーバ。
- クライアントdqin.rbはQueueサーバの知らないオブジェクト(DQEntry)を
- pushするがDRbUnknownによりクライアントdqout.rbがpopできる。
- * dqueue.rb --- server
- * dqin.rb --- client。DQEntryオブジェクトをpushする
- * dqout.rb --- client。DQEntryオブジェクトをpopする
- * dqlib.rb --- DQEntryを定義したライブラリ
-
-* 名前による参照
- IdConvをカスタマイズしてidでなく名前で参照する例
- * name.rb --- server
- * namec.rb --- client
-
-* extservのサンプル
- * extserv_test.rb
-
-* TimerIdConvの使用例
- * holders.rb --- server。ruby -d hodlers.rbとするとTimerIdConvを使用する。
- * holderc.rb --- client
-
-* rinda.rbの使用例
- * rinda_ts.rb --- TupleSpaceサーバ。
- * rindac.rb --- TupleSpaceのclientでアプリケーションのclient
- * rindas.rb --- TupleSpaceのclientでアプリケーションのserver
-
-* observerの使用例
- cdbiff - http://namazu.org/~satoru/cdbiff/
- * dbiff.rb --- dcdbiff server
- * dcdbiff.rb --- dcdbiff client
-
-* drbsslの使用例
- * drbssl_s.rb
- * drbssl_c.rb
-
-* DRbProtoclの追加例
- * http0.rb
- * http0serv.rb
-
-* ringの使用例
- * ring_place.rb
- * ring_echo.rb
diff --git a/sample/drb/README.rdoc b/sample/drb/README.rdoc
deleted file mode 100644
index 80ae910a8a..0000000000
--- a/sample/drb/README.rdoc
+++ /dev/null
@@ -1,56 +0,0 @@
-= Sample scripts
-
-* array and iteretor
- * darray.rb --- server
- * darrayc.rb --- client
-
-* simple chat
- * dchats.rb --- server
- * dchatc.rb --- client
-
-* distributed chasen (for Japanese)
- * dhasen.rb --- server
- * dhasenc.rb --- client
-
-* simple log server
- * dlogd.rb --- server
- * dlogc.rb --- client
-
-* Queue server, and DRbUnknown demo
- * dqueue.rb --- server
- * dqin.rb --- client. push DQEntry objects.
- * dqout.rb --- client. pop DQEntry objects.
- * dqlib.rb --- define DQEntry
-
-* IdConv customize demo: reference by name
- * name.rb --- server
- * namec.rb --- client
-
-* extserv
- * extserv_test.rb
-
-* IdConv customize demo 2: using TimerIdConv
- * holders.rb --- server
- * holderc.rb --- client
-
-* rinda, remote tuplespace
- * rinda_ts.rb --- TupleSpace server.
- * rindas.rb --- provide simple service via TupleSpace.
- * rindac.rb --- service user
-
-* observer
- cdbiff - http://namazu.org/~satoru/cdbiff/
- * dbiff.rb --- dcdbiff server
- * dcdbiff.rb --- dcdbiff client
-
-* drbssl
- * drbssl_s.rb
- * drbssl_c.rb
-
-* add DRbProtocl
- * http0.rb
- * http0serv.rb
-
-* Rinda::Ring
- * ring_place.rb
- * ring_echo.rb
diff --git a/sample/drb/acl.rb b/sample/drb/acl.rb
deleted file mode 100644
index d93eb9c1fc..0000000000
--- a/sample/drb/acl.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require 'drb/acl'
-
-list = %w(deny all
- allow 192.168.1.1
- allow ::ffff:192.168.1.2
- allow 192.168.1.3
-)
-
-addr = ["AF_INET", 10, "lc630", "192.168.1.3"]
-
-acl = ACL.new
-p acl.allow_addr?(addr)
-
-acl = ACL.new(list, ACL::DENY_ALLOW)
-p acl.allow_addr?(addr)
diff --git a/sample/drb/darray.rb b/sample/drb/darray.rb
deleted file mode 100644
index d2ac39513f..0000000000
--- a/sample/drb/darray.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-=begin
- distributed Ruby --- Array
- Copyright (c) 1999-2001 Masatoshi SEKI
-=end
-
-require 'drb/drb'
-
-here = ARGV.shift
-DRb.start_service(here, [1, 2, "III", 4, "five", 6])
-puts DRb.uri
-DRb.thread.join
-
diff --git a/sample/drb/darrayc.rb b/sample/drb/darrayc.rb
deleted file mode 100644
index 579e11564e..0000000000
--- a/sample/drb/darrayc.rb
+++ /dev/null
@@ -1,47 +0,0 @@
-=begin
- distributed Ruby --- Array client
- Copyright (c) 1999-2001 Masatoshi SEKI
-=end
-
-require 'drb/drb'
-
-there = ARGV.shift || raise("usage: #{$0} <server_uri>")
-
-DRb.start_service(nil, nil)
-ro = DRbObject.new(nil, there)
-p ro.size
-
-puts "# collect"
-a = ro.collect { |x|
- x + x
-}
-p a
-
-puts "# find"
-p ro.find { |x| x.kind_of? String }
-
-puts "# each, break"
-ro.each do |x|
- next if x == "five"
- puts x
-end
-
-puts "# each, break"
-ro.each do |x|
- break if x == "five"
- puts x
-end
-
-puts "# each, next"
-ro.each do |x|
- next if x == "five"
- puts x
-end
-
-puts "# each, redo"
-count = 0
-ro.each do |x|
- count += 1
- puts count
- redo if count == 3
-end
diff --git a/sample/drb/dbiff.rb b/sample/drb/dbiff.rb
deleted file mode 100644
index 290eb1d28b..0000000000
--- a/sample/drb/dbiff.rb
+++ /dev/null
@@ -1,51 +0,0 @@
-#
-# dbiff.rb - distributed cdbiff (server)
-# * original: cdbiff by Satoru Takabayashi <http://namazu.org/~satoru/cdbiff>
-
-require 'drb/drb'
-require 'drb/eq'
-require 'drb/observer'
-
-class Biff
- include DRb::DRbObservable
-
- def initialize(filename, interval)
- super()
- @filename = filename
- @interval = interval
- end
-
- def run
- last = Time.now
- while true
- begin
- sleep(@interval)
- current = File::mtime(@filename)
- if current > last
- changed
- begin
- notify_observers(@filename, current)
- rescue Error
- end
- last = current
- end
- rescue
- next
- end
- end
- end
-end
-
-def main
- filename = "/var/mail/#{ENV['USER']}"
- interval = 15
- uri = 'druby://:19903'
-
- biff = Biff.new(filename, interval)
-
- DRb.start_service(uri, biff)
- biff.run
-end
-
-main
-
diff --git a/sample/drb/dcdbiff.rb b/sample/drb/dcdbiff.rb
deleted file mode 100644
index 6a24680c33..0000000000
--- a/sample/drb/dcdbiff.rb
+++ /dev/null
@@ -1,43 +0,0 @@
-#
-# dcdbiff.rb - distributed cdbiff (client)
-# * original: cdbiff by Satoru Takabayashi <http://namazu.org/~satoru/cdbiff>
-
-require 'drb/drb'
-require 'drb/eq'
-
-class Notify
- include DRbUndumped
-
- def initialize(biff, command)
- @biff = biff
- @command = command
-
- @biff.add_observer(self)
- end
-
- def update(filename, time)
- p [filename, time] if $DEBUG
- system(@command)
- end
-
- def done
- begin
- @biff.delete_observer(self)
- rescue
- end
- end
-end
-
-def main
- command = 'eject'
- uri = 'druby://localhost:19903'
-
- DRb.start_service
- biff = DRbObject.new(nil, uri)
- notify = Notify.new(biff, command)
-
- trap("INT"){ notify.done }
- DRb.thread.join
-end
-
-main
diff --git a/sample/drb/dchatc.rb b/sample/drb/dchatc.rb
deleted file mode 100644
index 2b8ddbf4cc..0000000000
--- a/sample/drb/dchatc.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-=begin
- distributed Ruby --- chat client
- Copyright (c) 1999-2000 Masatoshi SEKI
-=end
-
-require 'drb/drb'
-
-class ChatClient
- include DRbUndumped
-
- def initialize(name)
- @name = name
- @key = nil
- end
- attr_reader(:name)
- attr_accessor(:key)
-
- def message(there, str)
- raise 'invalid key' unless @key == there
- puts str
- end
-end
-
-if __FILE__ == $0
- begin
- there = ARGV.shift
- name = ARGV.shift
- raise "usage" unless (there and name)
- rescue
- $stderr.puts("usage: #{$0} <server_uri> <your_name>")
- exit 1
- end
- DRb.start_service
- ro = DRbObject.new(nil, there)
-
- chat = ChatClient.new(name)
- entry = ro.add_member(chat)
- while gets
- entry.say($_)
- end
-end
diff --git a/sample/drb/dchats.rb b/sample/drb/dchats.rb
deleted file mode 100644
index c96486a452..0000000000
--- a/sample/drb/dchats.rb
+++ /dev/null
@@ -1,69 +0,0 @@
-=begin
- distributed Ruby --- chat server
- Copyright (c) 1999-2000 Masatoshi SEKI
-=end
-require 'drb/drb'
-
-class ChatEntry
- include DRbUndumped
-
- def initialize(server, there)
- @server = server
- @there = there
- @name = there.name
- @key = there.key = Time.now
- end
- attr :name, true
- attr :there
-
- def say(str)
- @server.distribute(@there, str)
- end
-
- def listen(str)
- @there.message(@key, str)
- end
-end
-
-
-class ChatServer
- def initialize
- @mutex = Thread::Mutex.new
- @members = {}
- end
-
- def add_member(there)
- client = ChatEntry.new(self, there)
- @mutex.synchronize do
- @members[there] = client
- end
- client
- end
-
- def distribute(there, str)
- name = @members[there].name
- msg = "<#{name}> #{str}"
- msg2 = ">#{name}< #{str}"
- @mutex.synchronize do
- for m in @members.keys
- begin
- if m == there
- @members[m].listen(msg2)
- else
- @members[m].listen(msg)
- end
- rescue
- p $!
- @members.delete(m)
- end
- end
- end
- end
-end
-
-if __FILE__ == $0
- here = ARGV.shift
- DRb.start_service(here, ChatServer.new)
- puts DRb.uri
- DRb.thread.join
-end
diff --git a/sample/drb/dhasen.rb b/sample/drb/dhasen.rb
deleted file mode 100644
index 13ff38940e..0000000000
--- a/sample/drb/dhasen.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-=begin
- distributed Ruby --- dRuby Sample Server --- chasen server
- Copyright (c) 1999-2001 Masatoshi SEKI
-=end
-
-=begin
- How to play.
-
- Terminal 1
- | % ruby dhasen.rb
- | druby://yourhost:7640
-
- Terminal 2
- | % ruby dhasenc.rb druby://yourhost:7640
-
-=end
-
-require 'drb/drb'
-require 'chasen'
-
-class Dhasen
- include DRbUndumped
-
- def initialize
- @mutex = Thread::Mutex.new
- end
-
- def sparse(str, *arg)
- @mutex.synchronize do
- Chasen.getopt(*arg)
- Chasen.sparse(str)
- end
- end
-end
-
-if __FILE__ == $0
- DRb.start_service(nil, Dhasen.new)
- puts DRb.uri
- DRb.thread.join
-end
-
diff --git a/sample/drb/dhasenc.rb b/sample/drb/dhasenc.rb
deleted file mode 100644
index dddac9882c..0000000000
--- a/sample/drb/dhasenc.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-# -*- coding: utf-8 -*-
-=begin
- distributed Ruby --- dRuby Sample Client -- chasen client
- Copyright (c) 1999-2001 Masatoshi SEKI
-=end
-
-require 'drb/drb'
-
-there = ARGV.shift || raise("usage: #{$0} <server_uri>")
-DRb.start_service
-dhasen = DRbObject.new(nil, there)
-
-print dhasen.sparse("本日は、晴天なり。", "-F", '(%BB %m %M)\n', "-j")
-print dhasen.sparse("本日は、晴天なり。", "-F", '(%m %M)\n')
diff --git a/sample/drb/dlogc.rb b/sample/drb/dlogc.rb
deleted file mode 100644
index 3939a71827..0000000000
--- a/sample/drb/dlogc.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-=begin
- distributed Ruby --- Log test
- Copyright (c) 1999-2001 Masatoshi SEKI
-=end
-
-require 'drb/drb'
-
-there = ARGV.shift || raise("usage: #{$0} <server_uri>")
-
-DRb.start_service
-ro = DRbObject.new(nil, there)
-ro.log(123)
-ro.log("hello")
-sleep 2
-ro.log("wakeup")
-
diff --git a/sample/drb/dlogd.rb b/sample/drb/dlogd.rb
deleted file mode 100644
index a87e660346..0000000000
--- a/sample/drb/dlogd.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-=begin
- distributed Ruby --- Log server
- Copyright (c) 1999-2000 Masatoshi SEKI
-=end
-
-require 'drb/drb'
-
-class Logger
- def initialize(fname)
- @fname = fname.to_s
- @fp = File.open(@fname, "a+")
- @queue = Thread::Queue.new
- @th = Thread.new { self.flush }
- end
-
- def log(str)
- @queue.push("#{Time.now}\t" + str.to_s)
- end
-
- def flush
- begin
- while(1)
- @fp.puts(@queue.pop)
- @fp.flush
- end
- ensure
- @fp.close
- end
- end
-end
-
-if __FILE__ == $0
- here = ARGV.shift
- DRb.start_service(here, Logger.new('/usr/tmp/dlogd.log'))
- puts DRb.uri
- DRb.thread.join
-end
-
diff --git a/sample/drb/dqin.rb b/sample/drb/dqin.rb
deleted file mode 100644
index 4751335fff..0000000000
--- a/sample/drb/dqin.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-=begin
- distributed Ruby --- store
- Copyright (c) 1999-2000 Masatoshi SEKI
-=end
-
-require 'drb/drb'
-require 'dqlib'
-
-there = ARGV.shift || raise("usage: #{$0} <server_uri>")
-
-DRb.start_service
-queue = DRbObject.new(nil, there)
-queue.push(DQEntry.new(DRb.uri))
diff --git a/sample/drb/dqlib.rb b/sample/drb/dqlib.rb
deleted file mode 100644
index 75f2e6115b..0000000000
--- a/sample/drb/dqlib.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-class DQEntry
- def initialize(name)
- @name = name
- end
-
- def greeting
- "Hello, This is #{@name}."
- end
- alias to_s greeting
-end
-
-if __FILE__ == $0
- puts DQEntry.new('DQEntry')
-end
diff --git a/sample/drb/dqout.rb b/sample/drb/dqout.rb
deleted file mode 100644
index f2b0b4ac95..0000000000
--- a/sample/drb/dqout.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-=begin
- distributed Ruby --- fetch
- Copyright (c) 1999-2000 Masatoshi SEKI
-=end
-
-require 'drb/drb'
-require 'dqlib'
-
-there = ARGV.shift || raise("usage: #{$0} <server_uri>")
-
-DRb.start_service
-queue = DRbObject.new(nil, there)
-entry = queue.pop
-puts entry.greeting
diff --git a/sample/drb/dqueue.rb b/sample/drb/dqueue.rb
deleted file mode 100644
index a9afa8c858..0000000000
--- a/sample/drb/dqueue.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-=begin
- distributed Ruby --- Queue
- Copyright (c) 1999-2000 Masatoshi SEKI
-=end
-
-require 'drb/drb'
-
-DRb.start_service(nil, Thread::Queue.new)
-puts DRb.uri
-DRb.thread.join
-
diff --git a/sample/drb/drbc.rb b/sample/drb/drbc.rb
deleted file mode 100644
index 50a86c39e8..0000000000
--- a/sample/drb/drbc.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-=begin
- distributed Ruby --- dRuby Sample Client
- Copyright (c) 1999-2000 Masatoshi SEKI
-=end
-
-require 'drb/drb'
-
-class DRbEx2
- include DRbUndumped
-
- def initialize(n)
- @n = n
- end
-
- def to_i
- @n.to_i
- end
-end
-
-if __FILE__ == $0
- there = ARGV.shift
- unless there
- $stderr.puts("usage: #{$0} <server_uri>")
- exit 1
- end
-
- DRb.start_service()
- ro = DRbObject.new_with_uri(there)
-
- puts ro
- p ro.to_a
- puts ro.hello
- p ro.hello
- puts ro.sample(DRbEx2.new(1), 2, 3)
- puts ro.sample(1, ro.sample(DRbEx2.new(1), 2, 3), DRbEx2.new(3))
-
- begin
- ro.err
- rescue DRb::DRbUnknownError
- p $!
- p $!.unknown
- rescue RuntimeError
- p $!
- end
-end
diff --git a/sample/drb/drbch.rb b/sample/drb/drbch.rb
deleted file mode 100644
index 07fdcd5fae..0000000000
--- a/sample/drb/drbch.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-=begin
- distributed Ruby --- dRuby Sample Client
- Copyright (c) 1999-2000 Masatoshi SEKI
-=end
-
-require 'drb/drb'
-require 'drb/http'
-
-class DRbEx2
- include DRbUndumped
-
- def initialize(n)
- @n = n
- end
-
- def to_i
- @n.to_i
- end
-end
-
-if __FILE__ == $0
- there = ARGV.shift
- unless there
- $stderr.puts("usage: #{$0} <server_uri>")
- exit 1
- end
-
- DRb::DRbConn.proxy_map['x68k'] = 'http://x68k/~mas/http_cgi.rb'
-
- DRb.start_service()
- ro = DRbObject.new(nil, there)
-
- puts ro
- p ro.to_a
- puts ro.hello
- p ro.hello
- puts ro.sample(DRbEx2.new(1), 2, 3)
- puts ro.sample(1, ro.sample(DRbEx2.new(1), 2, 3), DRbEx2.new(3))
-
- begin
- ro.err
- rescue DRb::DRbUnknownError
- p $!
- p $!.unknown
- rescue RuntimeError
- p $!
- end
-end
diff --git a/sample/drb/drbm.rb b/sample/drb/drbm.rb
deleted file mode 100644
index 3390608cd1..0000000000
--- a/sample/drb/drbm.rb
+++ /dev/null
@@ -1,60 +0,0 @@
-=begin
- multiple DRbServer
- Copyright (c) 1999-2002 Masatoshi SEKI
-=end
-
-=begin
- How to play.
-
- Terminal 1
- | % ruby drbm.rb
- | druby://yourhost:7640 druby://yourhost:7641
-
- Terminal 2
- | % ruby drbmc.rb druby://yourhost:7640 druby://yourhost:7641
- | [#<DRb::DRbObject .... @uri="druby://yourhost:7640">, "FOO"]
- | [#<DRb::DRbObject .... @uri="druby://yourhost:7641">, "FOO"]
-
-=end
-
-require 'drb/drb'
-
-class Hoge
- include DRbUndumped
- def initialize(s)
- @str = s
- end
-
- def to_s
- @str
- end
-end
-
-class Foo
- def initialize(s='FOO')
- @hoge = Hoge.new(s)
- end
-
- def hello
- @hoge
- end
-end
-
-class Bar < Foo
- def initialize(foo)
- @hoge = foo.hello
- end
-end
-
-
-if __FILE__ == $0
- foo = Foo.new
- s1 = DRb::DRbServer.new('druby://:7640', foo)
- s2 = DRb::DRbServer.new('druby://:7641', Bar.new(foo))
-
- puts "#{s1.uri} #{s2.uri}"
-
- s1.thread.join
- s2.thread.join
-end
-
diff --git a/sample/drb/drbmc.rb b/sample/drb/drbmc.rb
deleted file mode 100644
index fd191401e6..0000000000
--- a/sample/drb/drbmc.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-=begin
- multiple DRbServer client
- Copyright (c) 1999-2002 Masatoshi SEKI
-=end
-
-require 'drb/drb'
-
-if __FILE__ == $0
- s1 = ARGV.shift
- s2 = ARGV.shift
- unless s1 && s2
- $stderr.puts("usage: #{$0} <server_uri1> <server_uri2>")
- exit 1
- end
-
- DRb.start_service()
- r1 = DRbObject.new(nil, s1)
- r2 = DRbObject.new(nil, s2)
-
- p [r1.hello, r1.hello.to_s]
- p [r2.hello, r2.hello.to_s]
-end
diff --git a/sample/drb/drbs-acl.rb b/sample/drb/drbs-acl.rb
deleted file mode 100644
index 71c4f7bf42..0000000000
--- a/sample/drb/drbs-acl.rb
+++ /dev/null
@@ -1,51 +0,0 @@
-=begin
- distributed Ruby --- dRuby Sample Server
- Copyright (c) 1999-2000 Masatoshi SEKI
-=end
-
-=begin
- How to play.
-
- Terminal 1
- | % ruby drbs.rb
- | druby://yourhost:7640
-
- Terminal 2
- | % ruby drbc.rb druby://yourhost:7640
- | "hello"
- | 6
- | 10
-
-=end
-
-require 'drb/drb'
-require 'acl'
-
-class DRbEx
- def initialize
- @hello = 'hello'
- end
-
- def hello
- info = Thread.current['DRb']
- p info['socket'].peeraddr if info
- @hello
- end
-
- def sample(a, b, c)
- a.to_i + b.to_i + c.to_i
- end
-end
-
-if __FILE__ == $0
- acl = ACL.new(%w(deny all
- allow 192.168.1.*
- allow localhost))
-
- DRb.install_acl(acl)
-
- DRb.start_service(nil, DRbEx.new)
- puts DRb.uri
- DRb.thread.join
-end
-
diff --git a/sample/drb/drbs.rb b/sample/drb/drbs.rb
deleted file mode 100644
index 5a913d9918..0000000000
--- a/sample/drb/drbs.rb
+++ /dev/null
@@ -1,64 +0,0 @@
-=begin
- distributed Ruby --- dRuby Sample Server
- Copyright (c) 1999-2000,2002 Masatoshi SEKI
-=end
-
-=begin
- How to play.
-
- Terminal 1
- | % ruby drbs.rb
- | druby://yourhost:7640
-
- Terminal 2
- | % ruby drbc.rb druby://yourhost:7640
- | "hello"
- | ....
-
-=end
-
-require 'drb/drb'
-
-class DRbEx
- include DRbUndumped
-
- def initialize
- @hello = 'hello'
- end
-
- def hello
- cntxt = Thread.current['DRb']
- if cntxt
- p cntxt['server'].uri
- p cntxt['client'].peeraddr
- end
- Foo::Unknown.new
- end
-
- def err
- raise FooError
- end
-
- def sample(a, b, c)
- a.to_i + b.to_i + c.to_i
- end
-end
-
-class Foo
- class Unknown
- end
-end
-
-class FooError < RuntimeError
-end
-
-if __FILE__ == $0
- DRb.start_service(ARGV.shift || 'druby://:7640', DRbEx.new)
- puts DRb.uri
- Thread.new do
- sleep 10
- DRb.stop_service
- end
- DRb.thread.join
-end
-
diff --git a/sample/drb/drbssl_c.rb b/sample/drb/drbssl_c.rb
deleted file mode 100644
index 65112f6e78..0000000000
--- a/sample/drb/drbssl_c.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/usr/bin/env ruby
-
-require 'drb'
-require 'drb/ssl'
-
-there = ARGV.shift || "drbssl://localhost:3456"
-
-config = Hash.new
-config[:SSLVerifyMode] = OpenSSL::SSL::VERIFY_PEER
-config[:SSLVerifyCallback] = lambda{|ok,x509_store|
- p [ok, x509_store.error_string]
- true
-}
-
-DRb.start_service(nil,nil,config)
-h = DRbObject.new(nil, there)
-while line = gets
- p h.hello(line.chomp)
-end
diff --git a/sample/drb/drbssl_s.rb b/sample/drb/drbssl_s.rb
deleted file mode 100644
index 4d96f591d4..0000000000
--- a/sample/drb/drbssl_s.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-#!/usr/bin/env ruby
-
-require 'drb'
-require 'drb/ssl'
-
-here = ARGV.shift || "drbssl://localhost:3456"
-
-class HelloWorld
- include DRbUndumped
-
- def hello(name)
- "Hello, #{name}."
- end
-end
-
-config = Hash.new
-config[:verbose] = true
-begin
- data = open("sample.key"){|io| io.read }
- config[:SSLPrivateKey] = OpenSSL::PKey::RSA.new(data)
- data = open("sample.crt"){|io| io.read }
- config[:SSLCertificate] = OpenSSL::X509::Certificate.new(data)
-rescue
- $stderr.puts "Switching to use self-signed certificate"
- config[:SSLCertName] =
- [ ["C","JP"], ["O","Foo.DRuby.Org"], ["CN", "Sample"] ]
-end
-
-DRb.start_service(here, HelloWorld.new, config)
-puts DRb.uri
-DRb.thread.join
diff --git a/sample/drb/extserv_test.rb b/sample/drb/extserv_test.rb
deleted file mode 100644
index 2c4f485dc6..0000000000
--- a/sample/drb/extserv_test.rb
+++ /dev/null
@@ -1,80 +0,0 @@
-=begin
- dRuby sample
- Copyright (c) 2000 Masatoshi SEKI
-
-= How to play
-
-* Terminal 1
-
- % ruby -I. extserv_test.rb server
- druby://yourhost:12345
-
-* Terminal 2
-
- % ruby -I. extserv_test.rb druby://yourhost:12345
- ...
-
-=end
-
-require 'drb/drb'
-
-def ARGV.shift
- it = super()
- raise "usage:\nserver: #{$0} server [<uri>]\nclient: #{$0} [quit] <uri>" unless it
- it
-end
-
-class Foo
- include DRbUndumped
-
- def initialize(str)
- @str = str
- end
-
- def hello(it)
- "#{it}: #{self}"
- end
-
- def to_s
- @str
- end
-end
-
-cmd = ARGV.shift
-case cmd
-when 'itest1', 'itest2'
- require 'drb/extserv'
-
- front = Foo.new(cmd)
- server = DRb::DRbServer.new(nil, front)
- es = DRb::ExtServ.new(ARGV.shift, ARGV.shift, server)
- server.thread.join
-
-when 'server'
- require 'drb/extservm'
-
- DRb::ExtServManager.command['itest1'] = "ruby -I. #{$0} itest1"
- DRb::ExtServManager.command['itest2'] = "ruby -I. #{$0} itest2"
-
- s = DRb::ExtServManager.new
- DRb.start_service(ARGV.shift, s)
- puts DRb.uri
- DRb.thread.join
-
-
-else
- uri = (cmd == 'quit') ? ARGV.shift : cmd
-
- DRb.start_service
- s = DRbObject.new(nil, uri)
- t1 = s.service('itest1').front
- puts t1
- t2 = s.service('itest2').front
- puts t2
- puts t1.hello(t2)
- if (cmd == 'quit')
- s.service('itest1').stop_service
- s.service('itest2').stop_service
- end
-end
-
diff --git a/sample/drb/gw_ct.rb b/sample/drb/gw_ct.rb
deleted file mode 100644
index 0622784018..0000000000
--- a/sample/drb/gw_ct.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-require 'drb/drb'
-
-class Foo
- include DRbUndumped
-
- def foo(n)
- n + n
- end
-
- def bar(n)
- yield(n) + yield(n)
- end
-end
-
-DRb.start_service(nil)
-puts DRb.uri
-
-ro = DRbObject.new(nil, ARGV.shift)
-ro[:tcp] = Foo.new
-gets
-
-it = ro[:unix]
-p [it, it.foo(1)]
-gets
-
-p it.bar('2') {|n| n * 3}
-gets
-
-
diff --git a/sample/drb/gw_cu.rb b/sample/drb/gw_cu.rb
deleted file mode 100644
index 8079cbdc4f..0000000000
--- a/sample/drb/gw_cu.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-require 'drb/drb'
-require 'drb/unix'
-
-class Foo
- include DRbUndumped
-
- def foo(n)
- n + n
- end
-
- def bar(n)
- yield(n) + yield(n)
- end
-end
-
-DRb.start_service('drbunix:', nil)
-puts DRb.uri
-
-ro = DRbObject.new(nil, ARGV.shift)
-ro[:unix] = Foo.new
-gets
-
-it = ro[:tcp]
-p [it, it.foo(1)]
-gets
-
-p it.bar('2') {|n| n * 3}
-gets
diff --git a/sample/drb/gw_s.rb b/sample/drb/gw_s.rb
deleted file mode 100644
index c2bea0baad..0000000000
--- a/sample/drb/gw_s.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-require 'drb/drb'
-require 'drb/unix'
-require 'drb/gw'
-
-DRb.install_id_conv(DRb::GWIdConv.new)
-gw = DRb::GW.new
-s1 = DRb::DRbServer.new(ARGV.shift, gw)
-s2 = DRb::DRbServer.new(ARGV.shift, gw)
-s1.thread.join
-s2.thread.join
diff --git a/sample/drb/holderc.rb b/sample/drb/holderc.rb
deleted file mode 100644
index e627916d76..0000000000
--- a/sample/drb/holderc.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-require 'drb/drb'
-
-begin
- there = ARGV.shift || raise
-rescue
- $stderr.puts("usage: #{$0} <server_uri>")
- exit 1
-end
-
-DRb.start_service()
-ro = DRbObject.new(nil, there)
-
-ary = []
-10.times do
- ary.push(ro.gen)
-end
-
-sleep 5 if $DEBUG
-
-ary.each do |e|
- p e.sample([1])
-end
diff --git a/sample/drb/holders.rb b/sample/drb/holders.rb
deleted file mode 100644
index 293426faa5..0000000000
--- a/sample/drb/holders.rb
+++ /dev/null
@@ -1,63 +0,0 @@
-=begin
-= How to play.
-
-== with timeridconv:
- % ruby -d holders.rb
- druby://yourhost:1234
-
- % ruby holderc.rb druby://yourhost:1234
-
-
-== without timeridconv:
- % ruby holders.rb
- druby://yourhost:1234
-
- % ruby holderc.rb druby://yourhost:1234
-=end
-
-
-require 'drb/drb'
-
-class DRbEx3
- include DRbUndumped
-
- def initialize(n)
- @v = n
- end
-
- def sample(list)
- sum = 0
- list.each do |e|
- sum += e.to_i
- end
- @v * sum
- end
-end
-
-class DRbEx4
- include DRbUndumped
-
- def initialize
- @curr = 1
- end
-
- def gen
- begin
- @curr += 1
- DRbEx3.new(@curr)
- ensure
- GC.start
- end
- end
-end
-
-if __FILE__ == $0
- if $DEBUG
- require 'drb/timeridconv'
- DRb.install_id_conv(DRb::TimerIdConv.new(2))
- end
-
- DRb.start_service(nil, DRbEx4.new)
- puts DRb.uri
- DRb.thread.join
-end
diff --git a/sample/drb/http0.rb b/sample/drb/http0.rb
deleted file mode 100644
index e40d810311..0000000000
--- a/sample/drb/http0.rb
+++ /dev/null
@@ -1,77 +0,0 @@
-require 'drb/drb'
-require 'net/http'
-require 'uri'
-
-module DRb
- module HTTP0
- class StrStream
- def initialize(str='')
- @buf = str
- end
- attr_reader :buf
-
- def read(n)
- begin
- return @buf[0,n]
- ensure
- @buf[0,n] = ''
- end
- end
-
- def write(s)
- @buf.concat s
- end
- end
-
- def self.uri_option(uri, config)
- return uri, nil
- end
-
- def self.open(uri, config)
- unless /^http:/ =~ uri
- raise(DRbBadScheme, uri) unless uri =~ /^http:/
- raise(DRbBadURI, 'can\'t parse uri:' + uri)
- end
- ClientSide.new(uri, config)
- end
-
- class ClientSide
- def initialize(uri, config)
- @uri = uri
- @res = nil
- @config = config
- @msg = DRbMessage.new(config)
- @proxy = ENV['HTTP_PROXY']
- end
-
- def close; end
- def alive?; false; end
-
- def send_request(ref, msg_id, *arg, &b)
- stream = StrStream.new
- @msg.send_request(stream, ref, msg_id, *arg, &b)
- @reply_stream = StrStream.new
- post(@uri, stream.buf)
- end
-
- def recv_reply
- @msg.recv_reply(@reply_stream)
- end
-
- def post(url, data)
- it = URI.parse(url)
- path = [(it.path=='' ? '/' : it.path), it.query].compact.join('?')
- http = Net::HTTP.new(it.host, it.port)
- sio = StrStream.new
- http.post(path, data, {'Content-Type'=>'application/octetstream;'}) do |str|
- sio.write(str)
- if @config[:load_limit] < sio.buf.size
- raise TypeError, 'too large packet'
- end
- end
- @reply_stream = sio
- end
- end
- end
- DRbProtocol.add_protocol(HTTP0)
-end
diff --git a/sample/drb/http0serv.rb b/sample/drb/http0serv.rb
deleted file mode 100644
index 2e853312e1..0000000000
--- a/sample/drb/http0serv.rb
+++ /dev/null
@@ -1,120 +0,0 @@
-require 'webrick'
-require 'drb/drb'
-require_relative 'http0'
-
-module DRb
- module HTTP0
-
- def self.open_server(uri, config)
- unless /^http:/ =~ uri
- raise(DRbBadScheme, uri) unless uri =~ /^http:/
- raise(DRbBadURI, 'can\'t parse uri:' + uri)
- end
- Server.new(uri, config)
- end
-
- class Callback < WEBrick::HTTPServlet::AbstractServlet
- def initialize(config, drb)
- @config = config
- @drb = drb
- @queue = Thread::Queue.new
- end
-
- def do_POST(req, res)
- @req = req
- @res = res
- @drb.push(self)
- @res.body = @queue.pop
- @res['content-type'] = 'application/octet-stream;'
- end
-
- def req_body
- @req.body
- end
-
- def reply(body)
- @queue.push(body)
- end
-
- def close
- @queue.push('')
- end
- end
-
- class Server
- def initialize(uri, config)
- @uri = uri
- @config = config
- @queue = Thread::Queue.new
- setup_webrick(uri)
- end
- attr_reader :uri
-
- def close
- @server.shutdown if @server
- @server = nil
- end
-
- def push(callback)
- @queue.push(callback)
- end
-
- def accept
- client = @queue.pop
- ServerSide.new(uri, client, @config)
- end
-
- def setup_webrick(uri)
- logger = WEBrick::Log::new($stderr, WEBrick::Log::FATAL)
- u = URI.parse(uri)
- s = WEBrick::HTTPServer.new(:Port => u.port,
- :AddressFamily => Socket::AF_INET,
- :BindAddress => u.host,
- :Logger => logger,
- :ServerType => Thread)
- s.mount(u.path, Callback, self)
- @server = s
- s.start
- end
- end
-
- class ServerSide
- def initialize(uri, callback, config)
- @uri = uri
- @callback = callback
- @config = config
- @msg = DRbMessage.new(@config)
- @req_stream = StrStream.new(@callback.req_body)
- end
- attr_reader :uri
-
- def close
- @callback.close if @callback
- @callback = nil
- end
-
- def alive?; false; end
-
- def recv_request
- begin
- @msg.recv_request(@req_stream)
- rescue
- close
- raise $!
- end
- end
-
- def send_reply(succ, result)
- begin
- return unless @callback
- stream = StrStream.new
- @msg.send_reply(stream, succ, result)
- @callback.reply(stream.buf)
- rescue
- close
- raise $!
- end
- end
- end
- end
-end
diff --git a/sample/drb/name.rb b/sample/drb/name.rb
deleted file mode 100644
index 6d88186dab..0000000000
--- a/sample/drb/name.rb
+++ /dev/null
@@ -1,117 +0,0 @@
-=begin
- distributed Ruby --- NamedObject Sample
- Copyright (c) 2000-2001 Masatoshi SEKI
-=end
-
-=begin
-How to play.
-
-* start server
- Terminal 1
- | % ruby name.rb druby://yourhost:7640
- | druby://yourhost:7640
- | [return] to exit
-
-* start client
- Terminal 2
- | % ruby namec.rb druby://yourhost:7640
- | #<DRb::DRbObject:0x40164174 @uri="druby://yourhost:7640", @ref="seq">
- | #<DRb::DRbObject:0x40163c9c @uri="druby://yourhost:7640", @ref="mutex">
- | 1
- | 2
- | [return] to continue
-
-* restart server
- Terminal 1
- type [return]
- | % ruby name.rb druby://yourhost:7640
- | druby://yourhost:7640
- | [return] to exit
-
-* continue client
- Terminal 2
- type [return]
- | 1
- | 2
-=end
-
-require 'drb/drb'
-
-module DRbNamedObject
- DRbNAMEDICT = {}
- DRBNAMEMUTEX = Thread::Mutex.new
- attr_reader(:drb_name)
-
- def drb_name=(name)
- @drb_name = name
- DRBNAMEMUTEX.synchronize do
- raise(IndexError, name) if DRbNAMEDICT[name]
- DRbNAMEDICT[name] = self
- end
- end
-end
-
-class DRbNamedIdConv < DRb::DRbIdConv
- def initialize
- @dict = DRbNamedObject::DRbNAMEDICT
- end
-
- def to_obj(ref)
- @dict.fetch(ref) do super end
- end
-
- def to_id(obj)
- if obj.kind_of? DRbNamedObject
- return obj.drb_name
- else
- return super
- end
- end
-end
-
-class Seq
- include DRbUndumped
- include DRbNamedObject
-
- def initialize(v, name)
- @counter = v
- @mutex = Thread::Mutex.new
- self.drb_name = name
- end
-
- def next_value
- @mutex.synchronize do
- @counter += 1
- return @counter
- end
- end
-end
-
-class Front
- def initialize
- seq = Seq.new(0, 'seq')
- mutex = Thread::Mutex.new
- mutex.extend(DRbUndumped)
- mutex.extend(DRbNamedObject)
- mutex.drb_name = 'mutex'
- @name = {}
- @name['seq'] = seq
- @name['mutex'] = mutex
- end
-
- def [](k)
- @name[k]
- end
-end
-
-if __FILE__ == $0
- uri = ARGV.shift
-
- name_conv = DRbNamedIdConv.new
-
- DRb.install_id_conv(name_conv)
- DRb.start_service(uri, Front.new)
- puts DRb.uri
- DRb.thread.join
-end
-
diff --git a/sample/drb/namec.rb b/sample/drb/namec.rb
deleted file mode 100644
index 98b9d0e532..0000000000
--- a/sample/drb/namec.rb
+++ /dev/null
@@ -1,36 +0,0 @@
-=begin
- distributed Ruby --- NamedObject Sample Client
- Copyright (c) 2000-2001 Masatoshi SEKI
-=end
-
-require 'drb/drb'
-
-begin
- there = ARGV.shift || raise
-rescue
- puts "usage: #{$0} <server_uri>"
- exit 1
-end
-
-DRb.start_service()
-ro = DRbObject.new(nil, there)
-
-seq = ro["seq"]
-mutex = ro["mutex"]
-
-p seq
-p mutex
-
-mutex.synchronize do
- p seq.next_value
- p seq.next_value
-end
-
-puts '[return] to continue'
-gets
-
-mutex.synchronize do
- p seq.next_value
- p seq.next_value
-end
-
diff --git a/sample/drb/old_tuplespace.rb b/sample/drb/old_tuplespace.rb
deleted file mode 100644
index 2d5310086e..0000000000
--- a/sample/drb/old_tuplespace.rb
+++ /dev/null
@@ -1,212 +0,0 @@
-#!/usr/local/bin/ruby
-# TupleSpace
-# Copyright (c) 1999-2000 Masatoshi SEKI
-# You can redistribute it and/or modify it under the same terms as Ruby.
-
-class TupleSpace
- class Template
- def initialize(list)
- @list = list
- @check_idx = []
- @list.each_with_index do |x, i|
- @check_idx.push i if x
- end
- @size = @list.size
- end
-
- attr :size
- alias length size
-
- def match(tuple)
- return nil if tuple.size != self.size
- @check_idx.each do |i|
- unless @list[i] === tuple[i]
- return false
- end
- end
- return true
- end
- end
-
- def initialize
- @que = {}
- @waiting = {}
- @que.taint # enable tainted communication
- @waiting.taint
- self.taint
- end
-
- def wakeup_waiting(tuple)
- sz = tuple.length
- return nil unless @waiting[sz]
-
- x = nil
- i = -1
- found = false
- @waiting[sz] = @waiting[sz].find_all { |x|
- if x[0].match(tuple)
- begin
- x[1].wakeup
- rescue ThreadError
- end
- false
- else
- true
- end
- }
- end
-
- def put_waiting(template, thread)
- sz = template.length
- @waiting[sz] = [] unless @waiting[sz]
- @waiting[sz].push([Template.new(template), thread])
- end
- private :wakeup_waiting
- private :put_waiting
-
- def get_que(template)
- sz = template.length
- return nil unless @que[sz]
-
- template = Template.new(template)
-
- x = nil
- i = -1
- found = false
- @que[sz].each_with_index do |x, i|
- if template.match(x)
- found = true
- break
- end
- end
- return nil unless found
-
- @que[sz].delete_at(i)
-
- return x
- end
-
- def put_que(tuple)
- sz = tuple.length
- @que[sz] = [] unless @que[sz]
- @que[sz].push tuple
- end
- private :get_que
- private :put_que
-
- def out(*tuples)
- tuples.each do |tuple|
- Thread.critical = true
- put_que(tuple)
- wakeup_waiting(tuple)
- Thread.critical = false
- end
- end
- alias put out
- alias write out
-
- def in(template, non_block=false)
- begin
- loop do
- Thread.critical = true
- tuple = get_que(template)
- unless tuple
- if non_block
- raise ThreadError, "queue empty"
- end
- put_waiting(template, Thread.current)
- Thread.stop
- else
- return tuple
- end
- end
- ensure
- Thread.critical = false
- end
- end
- alias get in
- alias take in
-
- def rd(template, non_block=false)
- tuple = self.in(template, non_block)
- out(tuple)
- tuple
- end
- alias read rd
-
- def mv(dest, template, non_block=false)
- tuple = self.in(template, non_block)
- begin
- dest.out(tuple)
- rescue
- self.out(tuple)
- end
- end
- alias move mv
-end
-
-if __FILE__ == $0
- ts = TupleSpace.new
- clients = []
- servers = []
-
- def server(ts, id)
- Thread.start {
- loop do
- req = ts.in(['req', nil, nil])
- ac = req[1]
- num = req[2]
- sleep id
- ts.out([ac, id, num, num * num])
- end
- }
- end
-
- def client(ts, n)
- Thread.start {
- ac = Object.new
- tuples = (1..10).collect { |i|
- ['req', ac, i * 10 + n]
- }
- ts.out(*tuples)
- ts.out(tuples[0])
- puts "out: #{n}"
- 11.times do |i|
- ans = ts.in([ac, nil, nil, nil])
- puts "client(#{n}) server(#{ans[1]}) #{ans[2]} #{ans[3]}"
- end
- }
- end
-
- def watcher(ts)
- Thread.start {
- loop do
- begin
- sleep 1
- p ts.rd(['req', nil, nil], true)
- rescue ThreadError
- puts "'req' not found."
- end
- end
- }
- end
-
- (0..3).each do |n|
- servers.push(server(ts, n))
- end
-
- (1..6).each do |n|
- clients.push(client(ts, n))
- end
-
- (1..3).each do
- watcher(ts)
- end
-
- clients.each do |t|
- t.join
- end
-end
-
-
-
diff --git a/sample/drb/rinda_ts.rb b/sample/drb/rinda_ts.rb
deleted file mode 100644
index 6f2fae5c0f..0000000000
--- a/sample/drb/rinda_ts.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require 'drb/drb'
-require 'rinda/tuplespace'
-
-uri = ARGV.shift
-DRb.start_service(uri, Rinda::TupleSpace.new)
-puts DRb.uri
-DRb.thread.join
diff --git a/sample/drb/rindac.rb b/sample/drb/rindac.rb
deleted file mode 100644
index 72be09deaf..0000000000
--- a/sample/drb/rindac.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-require 'drb/drb'
-require 'rinda/rinda'
-
-uri = ARGV.shift || raise("usage: #{$0} <server_uri>")
-
-DRb.start_service
-ts = Rinda::TupleSpaceProxy.new(DRbObject.new(nil, uri))
-
-(1..10).each do |n|
- ts.write(['sum', DRb.uri, n])
-end
-
-(1..10).each do |n|
- ans = ts.take(['ans', DRb.uri, n, nil])
- p [ans[2], ans[3]]
-end
-
diff --git a/sample/drb/rindas.rb b/sample/drb/rindas.rb
deleted file mode 100644
index 9fd9ada2d1..0000000000
--- a/sample/drb/rindas.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-require 'drb/drb'
-require 'rinda/rinda'
-
-def do_it(v)
- puts "do_it(#{v})"
- v + v
-end
-
-uri = ARGV.shift || raise("usage: #{$0} <server_uri>")
-
-DRb.start_service
-ts = Rinda::TupleSpaceProxy.new(DRbObject.new(nil, uri))
-
-while true
- r = ts.take(['sum', nil, nil])
- v = do_it(r[2])
- ts.write(['ans', r[1], r[2], v])
-end
diff --git a/sample/drb/ring_echo.rb b/sample/drb/ring_echo.rb
deleted file mode 100644
index c54628b54c..0000000000
--- a/sample/drb/ring_echo.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-require 'drb/drb'
-require 'drb/eq'
-require 'rinda/ring'
-
-class RingEcho
- include DRbUndumped
- def initialize(name)
- @name = name
- end
-
- def echo(str)
- "#{@name}: #{str}"
- end
-end
-
-DRb.start_service
-
-renewer = Rinda::SimpleRenewer.new
-
-finder = Rinda::RingFinger.new
-ts = finder.lookup_ring_any
-ts.read_all([:name, :RingEcho, nil, nil]).each do |tuple|
- p tuple[2]
- puts tuple[2].echo('Hello, World') rescue nil
-end
-ts.write([:name, :RingEcho, RingEcho.new(DRb.uri), ''], renewer)
-
-DRb.thread.join
-
diff --git a/sample/drb/ring_inspect.rb b/sample/drb/ring_inspect.rb
deleted file mode 100644
index c096cd7034..0000000000
--- a/sample/drb/ring_inspect.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-require 'rinda/ring'
-require 'drb/drb'
-
-class Inspector
- def initialize
- end
-
- def primary
- Rinda::RingFinger.primary
- end
-
- def list_place
- Rinda::RingFinger.to_a
- end
-
- def list(idx = -1)
- if idx < 0
- ts = primary
- else
- ts = list_place[idx]
- raise "RingNotFound" unless ts
- end
- ts.read_all([:name, nil, nil, nil])
- end
-end
-
-def main
- DRb.start_service
- r = Inspector.new
-end
diff --git a/sample/drb/ring_place.rb b/sample/drb/ring_place.rb
deleted file mode 100644
index 11c6c2fe80..0000000000
--- a/sample/drb/ring_place.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-require 'drb/drb'
-require 'rinda/ring'
-require 'rinda/tuplespace'
-
-unless $DEBUG
- # Run as a daemon...
- exit!( 0 ) if fork
- Process.setsid
- exit!( 0 ) if fork
-end
-
-DRb.start_service(ARGV.shift)
-
-ts = Rinda::TupleSpace.new
-place = Rinda::RingServer.new(ts)
-
-if $DEBUG
- puts DRb.uri
- DRb.thread.join
-else
- STDIN.reopen(IO::NULL)
- STDOUT.reopen(IO::NULL, 'w')
- STDERR.reopen(IO::NULL, 'w')
- DRb.thread.join
-end
diff --git a/sample/drb/simpletuple.rb b/sample/drb/simpletuple.rb
deleted file mode 100644
index 4bb4b1cff9..0000000000
--- a/sample/drb/simpletuple.rb
+++ /dev/null
@@ -1,89 +0,0 @@
-#!/usr/local/bin/ruby
-# SimpleTupleSpace
-# Copyright (c) 1999-2000 Masatoshi SEKI
-# You can redistribute it and/or modify it under the same terms as Ruby.
-
-class SimpleTupleSpace
- def initialize
- @hash = {}
- @waiting = {}
- @hash.taint
- @waiting.taint
- self.taint
- end
-
- def out(key, obj)
- Thread.critical = true
- @hash[key] ||= []
- @waiting[key] ||= []
- @hash[key].push obj
- begin
- t = @waiting[key].shift
- @waiting.delete(key) if @waiting[key].length == 0
- t.wakeup if t
- rescue ThreadError
- retry
- ensure
- Thread.critical = false
- end
- end
-
- def in(key)
- Thread.critical = true
- @hash[key] ||= []
- @waiting[key] ||= []
- begin
- loop do
- if @hash[key].length == 0
- @waiting[key].push Thread.current
- Thread.stop
- else
- return @hash[key].shift
- end
- end
- ensure
- @hash.delete(key) if @hash[key].length == 0
- Thread.critical = false
- end
- end
-end
-
-if __FILE__ == $0
- ts = SimpleTupleSpace.new
- clients = []
- servers = []
-
- def server(ts)
- Thread.start {
- loop do
- req = ts.in('req')
- ac = req[0]
- num = req[1]
- ts.out(ac, num * num)
- end
- }
- end
-
- def client(ts, n)
- Thread.start {
- ac = Object.new
- ts.out('req', [ac, n])
- ans = ts.in(ac)
- puts "#{n}: #{ans}"
- }
- end
-
- 3.times do
- servers.push(server(ts))
- end
-
- (1..6).each do |n|
- clients.push(client(ts, n))
- end
-
- clients.each do |t|
- t.join
- end
-end
-
-
diff --git a/sample/drb/speedc.rb b/sample/drb/speedc.rb
deleted file mode 100644
index 64b8a65021..0000000000
--- a/sample/drb/speedc.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/usr/local/bin/ruby
-
-uri = ARGV.shift || raise("usage: #{$0} URI")
-N = (ARGV.shift || 100).to_i
-
-case uri
-when /^tcpromp:/, /^unixromp:/
- require 'romp'
-
- client = ROMP::Client.new(uri, false)
- foo = client.resolve("foo")
-when /^druby:/
- require 'drb/drb'
-
- DRb.start_service
- foo = DRbObject.new(nil, uri)
-end
-
-N.times do |n|
- foo.foo(n)
-end
diff --git a/sample/drb/speeds.rb b/sample/drb/speeds.rb
deleted file mode 100644
index 7984059423..0000000000
--- a/sample/drb/speeds.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-class Foo
- attr_reader :i
- def initialize
- @i = 0
- end
-
- def foo(i)
- @i = i
- i + i
- end
-end
-
-# server = ROMP::Server.new('tcpromp://localhost:4242', nil, true)
-
-uri = ARGV.shift || raise("usage: #{$0} URI")
-foo = Foo.new
-
-case uri
-when /^tcpromp:/, /^unixromp:/
- require 'romp'
-
- server = ROMP::Server.new(uri, nil, true)
- server.bind(foo, "foo")
-
-when /^druby:/
- require 'drb/drb'
-
- DRb.start_service(uri, Foo.new)
-end
-
-DRb.thread.join
diff --git a/sample/exyacc.rb b/sample/exyacc.rb
index 9a9435a0dc..cbcc18d58b 100644
--- a/sample/exyacc.rb
+++ b/sample/exyacc.rb
@@ -8,7 +8,7 @@ ARGF.each(nil) do |source|
grammar = source[sbeg, send-sbeg]
grammar.sub!(/.*\n/, "")
grammar.gsub!(/'\{'/, "'\001'")
- grammar.gsub!(/'\}'/, "'\002'")
+ grammar.gsub!(/["']\}["']/, "'\002'")
grammar.gsub!(%r{\*/}, "\003\003")
grammar.gsub!(%r{/\*[^\003]*\003\003}, '')
while grammar.gsub!(/\{[^{}]*\}/, ''); end
diff --git a/sample/from.rb b/sample/from.rb
index db1299c869..0e5a08de5f 100644
--- a/sample/from.rb
+++ b/sample/from.rb
@@ -62,7 +62,7 @@ def from_main
if File.exist?(file)
atime = File.atime(file)
mtime = File.mtime(file)
- open(file, "r") do |f|
+ File.open(file, "r") do |f|
until f.eof?
header = {}
f.each_line do |line|
diff --git a/sample/mine.rb b/sample/mine.rb
index a841d1a60a..77e0204bf6 100755
--- a/sample/mine.rb
+++ b/sample/mine.rb
@@ -1,6 +1,8 @@
#! /usr/bin/ruby -Ku
# -*- coding: utf-8 -*-
+require 'io/console'
+
class Board
def clr
print "\e[2J"
@@ -143,8 +145,8 @@ class Board
end
bd=Board.new(10,10,10)
-system("stty raw -echo")
-begin
+
+IO.console.raw do
loop do
case STDIN.getc
when ?n # new game
@@ -170,7 +172,5 @@ begin
bd.reset
end
end
-ensure
- system("stty -raw echo")
end
print "\n"
diff --git a/sample/mpart.rb b/sample/mpart.rb
index a88eba0ef6..eeb895d3de 100644
--- a/sample/mpart.rb
+++ b/sample/mpart.rb
@@ -2,11 +2,29 @@
# split into multi part
# usage: mpart.rb [-nnn] file..
+class MPart < File
+ def self.new(basename, extname, part, parts)
+ super(sprintf("%s.%s%02d", basename, extname, part), "w").
+ begin_mpart(basename, part, parts)
+ end
+
+ def begin_mpart(basename, part, parts)
+ printf("%s part%02d/%02d\n", basename, part, parts)
+ write("BEGIN--cut here--cut here\n")
+ self
+ end
+
+ def close
+ write("END--cut here--cut here\n")
+ super
+ end
+end
+
lines = 1000
if (ARGV[0] =~ /^-(\d+)$/ )
- lines = $1.to_i;
- ARGV.shift;
+ lines = $1.to_i
+ ARGV.shift
end
basename = ARGV[0]
@@ -14,31 +32,23 @@ extname = "part"
part = 1
line = 0
+ofp = nil
fline = 0
-for i in ifp = open(basename)
- fline = fline + 1
-end
-ifp.close
+File.foreach(basename) {fline += 1}
parts = fline / lines + 1
-for i in ifp = open(basename)
+File.foreach(basename) do |i|
if line == 0
- ofp = open(sprintf("%s.%s%02d", basename, extname, part), "w")
- printf(ofp, "%s part%02d/%02d\n", basename, part, parts)
- ofp.write("BEGIN--cut here--cut here\n")
+ ofp = MPart.new(basename, extname, part, parts)
end
ofp.write(i)
- line = line + 1
- if line >= lines and !ifp.eof?
- ofp.write("END--cut here--cut here\n")
+ line += 1
+ if line >= lines
ofp.close
- part = part + 1
+ part += 1
line = 0
end
end
-ofp.write("END--cut here--cut here\n")
ofp.close
-
-ifp.close
diff --git a/sample/net-imap.rb b/sample/net-imap.rb
deleted file mode 100644
index b93ecb746e..0000000000
--- a/sample/net-imap.rb
+++ /dev/null
@@ -1,167 +0,0 @@
-require 'net/imap'
-require "getoptlong"
-
-$stdout.sync = true
-$port = nil
-$user = ENV["USER"] || ENV["LOGNAME"]
-$auth = "login"
-$ssl = false
-$starttls = false
-
-def usage
- <<EOF
-usage: #{$0} [options] <host>
-
- --help print this message
- --port=PORT specifies port
- --user=USER specifies user
- --auth=AUTH specifies auth type
- --starttls use starttls
- --ssl use ssl
-EOF
-end
-
-begin
- require 'io/console'
-rescue LoadError
- def _noecho(&block)
- system("stty", "-echo")
- begin
- yield STDIN
- ensure
- system("stty", "echo")
- end
- end
-else
- def _noecho(&block)
- STDIN.noecho(&block)
- end
-end
-
-def get_password
- print "password: "
- begin
- return _noecho(&:gets).chomp
- ensure
- puts
- end
-end
-
-def get_command
- printf("%s@%s> ", $user, $host)
- if line = gets
- return line.strip.split(/\s+/)
- else
- return nil
- end
-end
-
-parser = GetoptLong.new
-parser.set_options(['--debug', GetoptLong::NO_ARGUMENT],
- ['--help', GetoptLong::NO_ARGUMENT],
- ['--port', GetoptLong::REQUIRED_ARGUMENT],
- ['--user', GetoptLong::REQUIRED_ARGUMENT],
- ['--auth', GetoptLong::REQUIRED_ARGUMENT],
- ['--starttls', GetoptLong::NO_ARGUMENT],
- ['--ssl', GetoptLong::NO_ARGUMENT])
-begin
- parser.each_option do |name, arg|
- case name
- when "--port"
- $port = arg
- when "--user"
- $user = arg
- when "--auth"
- $auth = arg
- when "--ssl"
- $ssl = true
- when "--starttls"
- $starttls = true
- when "--debug"
- Net::IMAP.debug = true
- when "--help"
- usage
- exit
- end
- end
-rescue
- abort usage
-end
-
-$host = ARGV.shift
-unless $host
- abort usage
-end
-
-imap = Net::IMAP.new($host, :port => $port, :ssl => $ssl)
-begin
- imap.starttls if $starttls
- class << password = method(:get_password)
- alias to_str call
- end
- imap.authenticate($auth, $user, password)
- while true
- cmd, *args = get_command
- break unless cmd
- begin
- case cmd
- when "list"
- for mbox in imap.list("", args[0] || "*")
- if mbox.attr.include?(Net::IMAP::NOSELECT)
- prefix = "!"
- elsif mbox.attr.include?(Net::IMAP::MARKED)
- prefix = "*"
- else
- prefix = " "
- end
- print prefix, mbox.name, "\n"
- end
- when "select"
- imap.select(args[0] || "inbox")
- print "ok\n"
- when "close"
- imap.close
- print "ok\n"
- when "summary"
- unless messages = imap.responses["EXISTS"][-1]
- puts "not selected"
- next
- end
- if messages > 0
- for data in imap.fetch(1..-1, ["ENVELOPE"])
- print data.seqno, ": ", data.attr["ENVELOPE"].subject, "\n"
- end
- else
- puts "no message"
- end
- when "fetch"
- if args[0]
- data = imap.fetch(args[0].to_i, ["RFC822.HEADER", "RFC822.TEXT"])[0]
- puts data.attr["RFC822.HEADER"]
- puts data.attr["RFC822.TEXT"]
- else
- puts "missing argument"
- end
- when "logout", "exit", "quit"
- break
- when "help", "?"
- print <<EOF
-list [pattern] list mailboxes
-select [mailbox] select mailbox
-close close mailbox
-summary display summary
-fetch [msgno] display message
-logout logout
-help, ? display help message
-EOF
- else
- print "unknown command: ", cmd, "\n"
- end
- rescue Net::IMAP::Error
- puts $!
- end
- end
-ensure
- imap.logout
- imap.disconnect
-end
diff --git a/sample/openssl/c_rehash.rb b/sample/openssl/c_rehash.rb
index de4b66e902..8b005bbb84 100644
--- a/sample/openssl/c_rehash.rb
+++ b/sample/openssl/c_rehash.rb
@@ -156,7 +156,7 @@ private
end
def hash_name(name)
- sprintf("%x", name.hash)
+ sprintf("%08x", name.hash)
end
def fingerprint(der)
diff --git a/sample/prism/find_calls.rb b/sample/prism/find_calls.rb
new file mode 100644
index 0000000000..30af56c719
--- /dev/null
+++ b/sample/prism/find_calls.rb
@@ -0,0 +1,105 @@
+# This script finds calls to a specific method with a certain keyword parameter
+# within a given source file.
+
+require "prism"
+require "pp"
+
+# For deprecation or refactoring purposes, it's often useful to find all of the
+# places that call a specific method with a specific k eyword parameter. This is
+# easily accomplished with a visitor such as this one.
+class QuxParameterVisitor < Prism::Visitor
+ def initialize(calls)
+ @calls = calls
+ end
+
+ def visit_call_node(node)
+ @calls << node if qux?(node)
+ super
+ end
+
+ private
+
+ def qux?(node)
+ # All nodes implement pattern matching, so you can use the `in` operator to
+ # pull out all of their individual fields. As you can see by this extensive
+ # pattern match, this is quite a powerful feature.
+ node in {
+ # This checks that the receiver is the constant Qux or the constant path
+ # ::Qux. We are assuming relative constants are fine in this case.
+ receiver: (
+ Prism::ConstantReadNode[name: :Qux] |
+ Prism::ConstantPathNode[parent: nil, name: :Qux]
+ ),
+ # This checks that the name of the method is qux. We purposefully are not
+ # checking the call operator (., ::, or &.) because we want all of them.
+ # In other ASTs, this would be multiple node types, but prism combines
+ # them all into one for convenience.
+ name: :qux,
+ arguments: Prism::ArgumentsNode[
+ # Here we're going to use the "find" pattern to find the keyword hash
+ # node that has the correct key.
+ arguments: [
+ *,
+ Prism::KeywordHashNode[
+ # Here we'll use another "find" pattern to find the key that we are
+ # specifically looking for.
+ elements: [
+ *,
+ # Finally, we can assert against the key itself. Note that we are
+ # not looking at the value of hash pair, because we are only
+ # specifically looking for a key.
+ Prism::AssocNode[key: Prism::SymbolNode[unescaped: "qux"]],
+ *
+ ]
+ ],
+ *
+ ]
+ ]
+ }
+ end
+end
+
+calls = []
+Prism.parse_stream(DATA).value.accept(QuxParameterVisitor.new(calls))
+
+calls.each do |call|
+ print "CallNode "
+ puts PP.pp(call.location, +"")
+ print " "
+ puts call.slice
+end
+
+# =>
+# CallNode (5,6)-(5,29)
+# Qux.qux(222, qux: true)
+# CallNode (9,6)-(9,30)
+# Qux&.qux(333, qux: true)
+# CallNode (20,6)-(20,51)
+# Qux::qux(888, qux: ::Qux.qux(999, qux: true))
+# CallNode (20,25)-(20,50)
+# ::Qux.qux(999, qux: true)
+
+__END__
+module Foo
+ class Bar
+ def baz1
+ Qux.qux(111)
+ Qux.qux(222, qux: true)
+ end
+
+ def baz2
+ Qux&.qux(333, qux: true)
+ Qux&.qux(444)
+ end
+
+ def baz3
+ qux(555, qux: false)
+ 666.qux(666)
+ end
+
+ def baz4
+ Qux::qux(777)
+ Qux::qux(888, qux: ::Qux.qux(999, qux: true))
+ end
+ end
+end
diff --git a/sample/prism/find_comments.rb b/sample/prism/find_comments.rb
new file mode 100644
index 0000000000..6a26cd32b7
--- /dev/null
+++ b/sample/prism/find_comments.rb
@@ -0,0 +1,100 @@
+# This script finds all of the comments within a given source file for a method.
+
+require "prism"
+
+class FindMethodComments < Prism::Visitor
+ def initialize(target, comments, nesting = [])
+ @target = target
+ @comments = comments
+ @nesting = nesting
+ end
+
+ # These visit methods are specific to each class. Defining a visitor allows
+ # you to group functionality that applies to all node types into a single
+ # class. You can find which method corresponds to which node type by looking
+ # at the class name, calling #type on the node, or by looking at the #accept
+ # method definition on the node.
+ def visit_module_node(node)
+ visitor = FindMethodComments.new(@target, @comments, [*@nesting, node.name])
+ node.compact_child_nodes.each { |child| child.accept(visitor) }
+ end
+
+ def visit_class_node(node)
+ # We could keep track of an internal state where we push the class name here
+ # and then pop it after the visit is complete. However, it is often simpler
+ # and cleaner to generate a new visitor instance when the state changes,
+ # because then the state is immutable and it's easier to reason about. This
+ # also provides for more debugging opportunity in the initializer.
+ visitor = FindMethodComments.new(@target, @comments, [*@nesting, node.name])
+ node.compact_child_nodes.each { |child| child.accept(visitor) }
+ end
+
+ def visit_def_node(node)
+ if [*@nesting, node.name] == @target
+ # Comments are always attached to locations (either inner locations on a
+ # node like the location of a keyword or the location on the node itself).
+ # Nodes are considered either "leading" or "trailing", which means that
+ # they occur before or after the location, respectively. In this case of
+ # documentation, we only want to consider leading comments. You can also
+ # fetch all of the comments on a location with #comments.
+ @comments.concat(node.location.leading_comments)
+ else
+ super
+ end
+ end
+end
+
+# Most of the time, the concept of "finding" something in the AST can be
+# accomplished either with a queue or with a visitor. In this case we will use a
+# visitor, but a queue would work just as well.
+def find_comments(result, path)
+ target = path.split(/::|#/).map(&:to_sym)
+ comments = []
+
+ result.value.accept(FindMethodComments.new(target, comments))
+ comments
+end
+
+result = Prism.parse_stream(DATA)
+result.attach_comments!
+
+find_comments(result, "Foo#foo").each do |comment|
+ puts comment.inspect
+ puts comment.slice
+end
+
+# =>
+# #<Prism::InlineComment @location=#<Prism::Location @start_offset=205 @length=27 start_line=13>>
+# # This is the documentation
+# #<Prism::InlineComment @location=#<Prism::Location @start_offset=235 @length=21 start_line=14>>
+# # for the foo method.
+
+find_comments(result, "Foo::Bar#bar").each do |comment|
+ puts comment.inspect
+ puts comment.slice
+end
+
+# =>
+# #<Prism::InlineComment @location=#<Prism::Location @start_offset=126 @length=23 start_line=7>>
+# # This is documentation
+# #<Prism::InlineComment @location=#<Prism::Location @start_offset=154 @length=21 start_line=8>>
+# # for the bar method.
+
+__END__
+# This is the documentation
+# for the Foo module.
+module Foo
+ # This is documentation
+ # for the Bar class.
+ class Bar
+ # This is documentation
+ # for the bar method.
+ def bar
+ end
+ end
+
+ # This is the documentation
+ # for the foo method.
+ def foo
+ end
+end
diff --git a/sample/prism/locate_nodes.rb b/sample/prism/locate_nodes.rb
new file mode 100644
index 0000000000..7a51db4367
--- /dev/null
+++ b/sample/prism/locate_nodes.rb
@@ -0,0 +1,84 @@
+# This script locates a set of nodes determined by a line and column (in bytes).
+
+require "prism"
+require "pp"
+
+# This method determines if the given location covers the given line and column.
+# It's important to note that columns (and offsets) in prism are always in
+# bytes. This is because prism supports all 90 source encodings that Ruby
+# supports. You can always retrieve the column (or offset) of a location in
+# other units with other provided APIs, like #start_character_column or
+# #start_code_units_column.
+def covers?(location, line:, column:)
+ start_line = location.start_line
+ end_line = location.end_line
+
+ if start_line == end_line
+ # If the location only spans one line, then we only check if the line
+ # matches and that the column is covered by the column range.
+ line == start_line && (location.start_column...location.end_column).cover?(column)
+ else
+ # Otherwise, we check that it is on the start line and the column is greater
+ # than or equal to the start column, or that it is on the end line and the
+ # column is less than the end column, or that it is between the start and
+ # end lines.
+ (line == start_line && column >= location.start_column) ||
+ (line == end_line && column < location.end_column) ||
+ (line > start_line && line < end_line)
+ end
+end
+
+# This method descends down into the AST whose root is `node` and returns the
+# array of all of the nodes that cover the given line and column.
+def locate(node, line:, column:)
+ queue = [node]
+ result = []
+
+ # We could use a recursive method here instead if we wanted, but it's
+ # important to note that that will not work for ASTs that are nested deeply
+ # enough to cause a stack overflow.
+ while (node = queue.shift)
+ result << node
+
+ # Nodes have `child_nodes` and `compact_child_nodes`. `child_nodes` have
+ # consistent indices but include `nil` for optional fields that are not
+ # present, whereas `compact_child_nodes` has inconsistent indices but does
+ # not include `nil` for optional fields that are not present.
+ node.compact_child_nodes.find do |child|
+ queue << child if covers?(child.location, line: line, column: column)
+ end
+ end
+
+ result
+end
+
+result = Prism.parse_stream(DATA)
+locate(result.value, line: 4, column: 14).each_with_index do |node, index|
+ print " " * index
+ print node.class.name.split("::", 2).last
+ print " "
+ puts PP.pp(node.location, +"")
+end
+
+# =>
+# ProgramNode (1,0)-(7,3)
+# StatementsNode (1,0)-(7,3)
+# ModuleNode (1,0)-(7,3)
+# StatementsNode (2,2)-(6,5)
+# ClassNode (2,2)-(6,5)
+# StatementsNode (3,4)-(5,7)
+# DefNode (3,4)-(5,7)
+# StatementsNode (4,6)-(4,21)
+# CallNode (4,6)-(4,21)
+# CallNode (4,6)-(4,15)
+# ArgumentsNode (4,12)-(4,15)
+# IntegerNode (4,12)-(4,15)
+
+__END__
+module Foo
+ class Bar
+ def baz
+ 111 + 222 + 333
+ end
+ end
+end
diff --git a/sample/prism/make_tags.rb b/sample/prism/make_tags.rb
new file mode 100644
index 0000000000..dc770ab1b0
--- /dev/null
+++ b/sample/prism/make_tags.rb
@@ -0,0 +1,302 @@
+# This script generates a tags file using Prism to parse the Ruby files.
+
+require "prism"
+
+# This visitor is responsible for visiting the nodes in the AST and generating
+# the appropriate tags. The tags are stored in the entries array as strings.
+class TagsVisitor < Prism::Visitor
+ # This represents an entry in the tags file, which is a tab-separated line. It
+ # houses the logic for how an entry is constructed.
+ class Entry
+ attr_reader :parts
+
+ def initialize(name, filepath, pattern, type)
+ @parts = [name, filepath, pattern, type]
+ end
+
+ def attribute(key, value)
+ parts << "#{key}:#{value}"
+ end
+
+ def attribute_class(nesting, names)
+ return if nesting.empty? && names.length == 1
+ attribute("class", [*nesting, names].flatten.tap(&:pop).join("."))
+ end
+
+ def attribute_inherits(names)
+ attribute("inherits", names.join(".")) if names
+ end
+
+ def to_line
+ parts.join("\t")
+ end
+ end
+
+ private_constant :Entry
+
+ attr_reader :entries, :filepath, :lines, :nesting, :singleton
+
+ # Initialize the visitor with the given parameters. The first three parameters
+ # are constant throughout the visit, while the last two are controlled by the
+ # visitor as it traverses the AST. These are treated as immutable by virtue of
+ # the visit methods constructing new visitors when they need to change.
+ def initialize(entries, filepath, lines, nesting = [], singleton = false)
+ @entries = entries
+ @filepath = filepath
+ @lines = lines
+ @nesting = nesting
+ @singleton = singleton
+ end
+
+ # Visit a method alias node and generate the appropriate tags.
+ #
+ # alias m2 m1
+ #
+ def visit_alias_method_node(node)
+ enter(node.new_name.unescaped.to_sym, node, "a") do |entry|
+ entry.attribute_class(nesting, [nil])
+ end
+
+ super
+ end
+
+ # Visit a method call to attr_reader, attr_writer, or attr_accessor without a
+ # receiver and generate the appropriate tags. Note that this ignores the fact
+ # that these methods could be overridden, which is a limitation of this
+ # script.
+ #
+ # attr_accessor :m1
+ #
+ def visit_call_node(node)
+ if !node.receiver && %i[attr_reader attr_writer attr_accessor].include?(name = node.name)
+ (node.arguments&.arguments || []).grep(Prism::SymbolNode).each do |argument|
+ if name != :attr_writer
+ enter(:"#{argument.unescaped}", argument, singleton ? "F" : "f") do |entry|
+ entry.attribute_class(nesting, [nil])
+ end
+ end
+
+ if name != :attr_reader
+ enter(:"#{argument.unescaped}=", argument, singleton ? "F" : "f") do |entry|
+ entry.attribute_class(nesting, [nil])
+ end
+ end
+ end
+ end
+
+ super
+ end
+
+ # Visit a class node and generate the appropriate tags.
+ #
+ # class C1
+ # end
+ #
+ def visit_class_node(node)
+ if (names = names_for(node.constant_path))
+ enter(names.last, node, "c") do |entry|
+ entry.attribute_class(nesting, names)
+ entry.attribute_inherits(names_for(node.superclass))
+ end
+
+ node.body&.accept(copy_visitor([*nesting, names], singleton))
+ end
+ end
+
+ # Visit a constant path write node and generate the appropriate tags.
+ #
+ # C1::C2 = 1
+ #
+ def visit_constant_path_write_node(node)
+ if (names = names_for(node.target))
+ enter(names.last, node, "C") do |entry|
+ entry.attribute_class(nesting, names)
+ end
+ end
+
+ super
+ end
+
+ # Visit a constant write node and generate the appropriate tags.
+ #
+ # C1 = 1
+ #
+ def visit_constant_write_node(node)
+ enter(node.name, node, "C") do |entry|
+ entry.attribute_class(nesting, [nil])
+ end
+
+ super
+ end
+
+ # Visit a method definition node and generate the appropriate tags.
+ #
+ # def m1; end
+ #
+ def visit_def_node(node)
+ enter(node.name, node, (node.receiver || singleton) ? "F" : "f") do |entry|
+ entry.attribute_class(nesting, [nil])
+ end
+
+ super
+ end
+
+ # Visit a module node and generate the appropriate tags.
+ #
+ # module M1
+ # end
+ #
+ def visit_module_node(node)
+ if (names = names_for(node.constant_path))
+ enter(names.last, node, "m") do |entry|
+ entry.attribute_class(nesting, names)
+ end
+
+ node.body&.accept(copy_visitor([*nesting, names], singleton))
+ end
+ end
+
+ # Visit a singleton class node and generate the appropriate tags.
+ #
+ # class << self
+ # end
+ #
+ def visit_singleton_class_node(node)
+ case node.expression
+ when Prism::SelfNode
+ node.body&.accept(copy_visitor(nesting, true))
+ when Prism::ConstantReadNode, Prism::ConstantPathNode
+ if (names = names_for(node.expression))
+ node.body&.accept(copy_visitor([*nesting, names], true))
+ end
+ else
+ node.body&.accept(copy_visitor([*nesting, nil], true))
+ end
+ end
+
+ private
+
+ # Generate a new visitor with the given dynamic options. The static options
+ # are copied over automatically.
+ def copy_visitor(nesting, singleton)
+ TagsVisitor.new(entries, filepath, lines, nesting, singleton)
+ end
+
+ # Generate a new entry for the given name, node, and type and add it into the
+ # list of entries. The block is used to add additional attributes to the
+ # entry.
+ def enter(name, node, type)
+ line = lines[node.location.start_line - 1].chomp
+ pattern = "/^#{line.gsub("\\", "\\\\\\\\").gsub("/", "\\/")}$/;\""
+
+ entry = Entry.new(name, filepath, pattern, type)
+ yield entry
+
+ entries << entry.to_line
+ end
+
+ # Retrieve the names for the given node. This is used to construct the class
+ # attribute for the tags.
+ def names_for(node)
+ case node
+ when Prism::ConstantPathNode
+ names = names_for(node.parent)
+ return unless names
+
+ names << node.name
+ when Prism::ConstantReadNode
+ [node.name]
+ when Prism::SelfNode
+ [:self]
+ else
+ # dynamic
+ end
+ end
+end
+
+# Parse the Ruby file and visit all of the nodes in the resulting AST. Once all
+# of the nodes have been visited, the entries array should be populated with the
+# tags.
+result = Prism.parse_stream(DATA)
+result.value.accept(TagsVisitor.new(entries = [], __FILE__, result.source.lines))
+
+# Print the tags to STDOUT.
+puts "!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;\" to lines/"
+puts "!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/"
+puts entries.sort
+
+# =>
+# !_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
+# !_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
+# C1 sample/prism/make_tags.rb /^ class C1$/;" c class:M1.M2
+# C2 sample/prism/make_tags.rb /^ class C2 < Object$/;" c class:M1.M2.C1 inherits:Object
+# C6 sample/prism/make_tags.rb /^ C6 = 1$/;" C class:M1
+# C7 sample/prism/make_tags.rb /^ C7 = 2$/;" C class:M1
+# C9 sample/prism/make_tags.rb /^ C8::C9 = 3$/;" C class:M1.C8
+# M1 sample/prism/make_tags.rb /^module M1$/;" m
+# M2 sample/prism/make_tags.rb /^ module M2$/;" m class:M1
+# M4 sample/prism/make_tags.rb /^ module M3::M4$/;" m class:M1.M3
+# M5 sample/prism/make_tags.rb /^ module self::M5$/;" m class:M1.self
+# m1 sample/prism/make_tags.rb /^ def m1; end$/;" f class:M1.M2.C1.C2
+# m10 sample/prism/make_tags.rb /^ attr_accessor :m10, :m11$/;" f class:M1.M3.M4
+# m10= sample/prism/make_tags.rb /^ attr_accessor :m10, :m11$/;" f class:M1.M3.M4
+# m11 sample/prism/make_tags.rb /^ attr_accessor :m10, :m11$/;" f class:M1.M3.M4
+# m11= sample/prism/make_tags.rb /^ attr_accessor :m10, :m11$/;" f class:M1.M3.M4
+# m12 sample/prism/make_tags.rb /^ attr_reader :m12, :m13, :m14$/;" f class:M1.M3.M4
+# m13 sample/prism/make_tags.rb /^ attr_reader :m12, :m13, :m14$/;" f class:M1.M3.M4
+# m14 sample/prism/make_tags.rb /^ attr_reader :m12, :m13, :m14$/;" f class:M1.M3.M4
+# m15= sample/prism/make_tags.rb /^ attr_writer :m15$/;" f class:M1.M3.M4
+# m2 sample/prism/make_tags.rb /^ def m2; end$/;" f class:M1.M2.C1.C2
+# m3 sample/prism/make_tags.rb /^ alias m3 m1$/;" a class:M1.M2.C1.C2
+# m4 sample/prism/make_tags.rb /^ alias :m4 :m2$/;" a class:M1.M2.C1.C2
+# m5 sample/prism/make_tags.rb /^ def self.m5; end$/;" F class:M1.M2.C1.C2
+# m6 sample/prism/make_tags.rb /^ def m6; end$/;" F class:M1.M2.C1.C2
+# m7 sample/prism/make_tags.rb /^ def m7; end$/;" F class:M1.M2.C1.C2.C3
+# m8 sample/prism/make_tags.rb /^ def m8; end$/;" F class:M1.M2.C1.C2.C4.C5
+# m9 sample/prism/make_tags.rb /^ def m9; end$/;" F class:M1.M2.C1.C2.
+
+__END__
+module M1
+ module M2
+ class C1
+ class C2 < Object
+ def m1; end
+ def m2; end
+
+ alias m3 m1
+ alias :m4 :m2
+
+ def self.m5; end
+
+ class << self
+ def m6; end
+ end
+
+ class << C3
+ def m7; end
+ end
+
+ class << C4::C5
+ def m8; end
+ end
+
+ class << c
+ def m9; end
+ end
+ end
+ end
+ end
+
+ module M3::M4
+ attr_accessor :m10, :m11
+ attr_reader :m12, :m13, :m14
+ attr_writer :m15
+ end
+
+ module self::M5
+ end
+
+ C6 = 1
+ C7 = 2
+ C8::C9 = 3
+end
diff --git a/sample/prism/multiplex_constants.rb b/sample/prism/multiplex_constants.rb
new file mode 100644
index 0000000000..e39f2c36f6
--- /dev/null
+++ b/sample/prism/multiplex_constants.rb
@@ -0,0 +1,138 @@
+# This script indexes the classes and modules within a set of files using the
+# saved source functionality.
+
+require "prism"
+require "etc"
+require "tempfile"
+
+module Indexer
+ # A class that implements the #enter functionality so that it can be passed to
+ # the various save* APIs. This effectively bundles up all of the node_id and
+ # field_name pairs so that they can be written back to the parent process.
+ class Repository
+ attr_reader :scope, :entries
+
+ def initialize
+ @scope = []
+ @entries = []
+ end
+
+ def with(next_scope)
+ previous_scope = scope
+ @scope = scope + next_scope
+ yield
+ @scope = previous_scope
+ end
+
+ def empty?
+ entries.empty?
+ end
+
+ def enter(node_id, field_name)
+ entries << [scope.join("::"), node_id, field_name]
+ end
+ end
+
+ # Visit the classes and modules in the AST and save their locations into the
+ # repository.
+ class Visitor < Prism::Visitor
+ attr_reader :repository
+
+ def initialize(repository)
+ @repository = repository
+ end
+
+ def visit_class_node(node)
+ repository.with(node.constant_path.full_name_parts) do
+ node.constant_path.save_location(repository)
+ visit(node.body)
+ end
+ end
+
+ def visit_module_node(node)
+ repository.with(node.constant_path.full_name_parts) do
+ node.constant_path.save_location(repository)
+ visit(node.body)
+ end
+ end
+ end
+
+ # Index the classes and modules within a file. If there are any entries,
+ # return them as a serialized string to the parent process.
+ def self.index(filepath)
+ repository = Repository.new
+ Prism.parse_file(filepath).value.accept(Visitor.new(repository))
+ "#{filepath}|#{repository.entries.join("|")}" unless repository.empty?
+ end
+end
+
+def index_glob(glob, count = Etc.nprocessors - 1)
+ process_ids = []
+ filepath_writers = []
+ index_reader, index_writer = IO.pipe
+
+ # For each number in count, fork off a worker that has access to two pipes.
+ # The first pipe is the index_writer, to which it writes all of the results of
+ # indexing the various files. The second pipe is the filepath_reader, from
+ # which it reads the filepaths that it needs to index.
+ count.times do
+ filepath_reader, filepath_writer = IO.pipe
+
+ process_ids << fork do
+ filepath_writer.close
+ index_reader.close
+
+ while (filepath = filepath_reader.gets(chomp: true))
+ results = Indexer.index(filepath)
+ index_writer.puts(results) if results
+ end
+ end
+
+ filepath_reader.close
+ filepath_writers << filepath_writer
+ end
+
+ index_writer.close
+
+ # In a separate thread, write all of the filepaths to the various worker
+ # processes. This is done in a separate threads since puts will eventually
+ # block when each of the pipe buffers fills up. We write in a round-robin
+ # fashion to the various workers. This could be improved using a work-stealing
+ # algorithm, but is fine if you don't end up having a ton of variety in the
+ # size of your files.
+ writer_thread =
+ Thread.new do
+ Dir[glob].each_with_index do |filepath, index|
+ filepath_writers[index % count].puts(filepath)
+ end
+ end
+
+ index = Hash.new { |hash, key| hash[key] = [] }
+
+ # In a separate thread, read all of the results from the various worker
+ # processes and store them in the index. This is done in a separate thread so
+ # that reads and writes can be interleaved. This is important so that the
+ # index pipe doesn't fill up and block the writer.
+ reader_thread =
+ Thread.new do
+ while (line = index_reader.gets(chomp: true))
+ filepath, *entries = line.split("|")
+ repository = Prism::Relocation.filepath(filepath).filepath.lines.code_unit_columns(Encoding::UTF_16LE).leading_comments
+
+ entries.each_slice(3) do |(name, node_id, field_name)|
+ index[name] << repository.enter(Integer(node_id), field_name.to_sym)
+ end
+ end
+ end
+
+ writer_thread.join
+ filepath_writers.each(&:close)
+
+ reader_thread.join
+ index_reader.close
+
+ process_ids.each { |process_id| Process.wait(process_id) }
+ index
+end
+
+index_glob(File.expand_path("../../lib/**/*.rb", __dir__))
diff --git a/sample/prism/relocate_constants.rb b/sample/prism/relocate_constants.rb
new file mode 100644
index 0000000000..faa48f6388
--- /dev/null
+++ b/sample/prism/relocate_constants.rb
@@ -0,0 +1,43 @@
+# This script finds the declaration of all classes and modules and stores them
+# in a hash for an in-memory database of constants.
+
+require "prism"
+
+class RelocationVisitor < Prism::Visitor
+ attr_reader :index, :repository, :scope
+
+ def initialize(index, repository, scope = [])
+ @index = index
+ @repository = repository
+ @scope = scope
+ end
+
+ def visit_class_node(node)
+ next_scope = scope + node.constant_path.full_name_parts
+ index[next_scope.join("::")] << node.constant_path.save(repository)
+ node.body&.accept(RelocationVisitor.new(index, repository, next_scope))
+ end
+
+ def visit_module_node(node)
+ next_scope = scope + node.constant_path.full_name_parts
+ index[next_scope.join("::")] << node.constant_path.save(repository)
+ node.body&.accept(RelocationVisitor.new(index, repository, next_scope))
+ end
+end
+
+# Create an index that will store a mapping between the names of constants to a
+# list of the locations where they are declared or re-opened.
+index = Hash.new { |hash, key| hash[key] = [] }
+
+# Loop through every file in the lib directory of this repository and parse them
+# with Prism. Then visit them using the RelocateVisitor to store their
+# repository entries in the index.
+Dir[File.expand_path("../../lib/**/*.rb", __dir__)].each do |filepath|
+ repository = Prism::Relocation.filepath(filepath).filepath.lines.code_unit_columns(Encoding::UTF_16LE)
+ Prism.parse_file(filepath).value.accept(RelocationVisitor.new(index, repository))
+end
+
+puts index["Prism::ParametersNode"].map { |entry| "#{entry.filepath}:#{entry.start_line}:#{entry.start_code_units_column}" }
+# =>
+# prism/lib/prism/node.rb:13889:8
+# prism/lib/prism/node_ext.rb:267:8
diff --git a/sample/prism/visit_nodes.rb b/sample/prism/visit_nodes.rb
new file mode 100644
index 0000000000..5ba703b0a3
--- /dev/null
+++ b/sample/prism/visit_nodes.rb
@@ -0,0 +1,63 @@
+# This script visits all of the nodes of a specific type within a given source
+# file. It uses the visitor class to traverse the AST.
+
+require "prism"
+require "pp"
+
+class CaseInsensitiveRegularExpressionVisitor < Prism::Visitor
+ def initialize(regexps)
+ @regexps = regexps
+ end
+
+ # As the visitor is walking the tree, this method will only be called when it
+ # encounters a regular expression node. We can then call any regular
+ # expression -specific APIs. In this case, we are only interested in the
+ # regular expressions that are case-insensitive, which we can retrieve with
+ # the #ignore_case? method.
+ def visit_regular_expression_node(node)
+ @regexps << node if node.ignore_case?
+ super
+ end
+
+ def visit_interpolated_regular_expression_node(node)
+ @regexps << node if node.ignore_case?
+
+ # The default behavior of the visitor is to continue visiting the children
+ # of the node. Because Ruby is so dynamic, it's actually possible for
+ # another regular expression to be interpolated in statements contained
+ # within the #{} contained in this interpolated regular expression node. By
+ # calling `super`, we ensure the visitor will continue. Failing to call
+ # `super` will cause the visitor to stop the traversal of the tree, which
+ # can also be useful in some cases.
+ super
+ end
+end
+
+result = Prism.parse_stream(DATA)
+regexps = []
+
+result.value.accept(CaseInsensitiveRegularExpressionVisitor.new(regexps))
+regexps.each do |node|
+ print node.class.name.split("::", 2).last
+ print " "
+ puts PP.pp(node.location, +"")
+
+ if node.is_a?(Prism::RegularExpressionNode)
+ print " "
+ p node.unescaped
+ end
+end
+
+# =>
+# InterpolatedRegularExpressionNode (3,9)-(3,47)
+# RegularExpressionNode (3,16)-(3,22)
+# "bar"
+# RegularExpressionNode (4,9)-(4,15)
+# "bar"
+
+__END__
+class Foo
+ REG1 = /foo/
+ REG2 = /foo #{/bar/i =~ "" ? "bar" : "baz"}/i
+ REG3 = /bar/i
+end
diff --git a/sample/trick2015/kinaba/entry.rb b/sample/trick2015/kinaba/entry.rb
index aa077dc240..2a75888ef5 100644
--- a/sample/trick2015/kinaba/entry.rb
+++ b/sample/trick2015/kinaba/entry.rb
@@ -54,8 +54,8 @@ while 0x00012345 >= $counter
srand +big && $counter >> 0b1
Enumerable
- Fixnum
- Bignum
+ String
+ Struct
Math
Complex
Comparable
diff --git a/sample/trick2018/02-mame/entry.rb b/sample/trick2018/02-mame/entry.rb
index cc4ef9cbc4..ced791aa3d 100644
--- a/sample/trick2018/02-mame/entry.rb
+++ b/sample/trick2018/02-mame/entry.rb
@@ -1,11 +1,11 @@
'';eval(r=%q(->z{r="'';eval(r=\
-%q(#{r}))[%q`#{z}`]";i=-040;30.
+%q(#{r}))[%q`#{z}`]";i=-040;31.
times{|n|(15+n%2*15-n/2).times{
r<<r[i+=(1.-n&2)*(32-n%2*31)]}}
i=r[524,0]=?\0;eval(r[479..-1])
c['"']}))[%q`GFEDCBA"+"[e\"'"'t
kE*;;\";" TRICK2018 ";tb,;{{r
-2E0$ob[us@*0)[90,336])_#i\n}s#i
+2E0$ob[us@*0)[90,336])#_i\n}s#i
0H}>["t]];};o[1,?\n*8];ex"-}eac
1Hl<1[-1]*2*t=n%2];o[14-n,0)mvk
8M$<4,?\n];15.times{|n|;o[35ie2
diff --git a/sample/trick2022/01-tompng/Gemfile b/sample/trick2022/01-tompng/Gemfile
new file mode 100644
index 0000000000..982b9de67f
--- /dev/null
+++ b/sample/trick2022/01-tompng/Gemfile
@@ -0,0 +1,2 @@
+source 'https://rubygems.org'
+gem 'matrix'
diff --git a/sample/trick2022/01-tompng/Gemfile.lock b/sample/trick2022/01-tompng/Gemfile.lock
new file mode 100644
index 0000000000..8bb3c69025
--- /dev/null
+++ b/sample/trick2022/01-tompng/Gemfile.lock
@@ -0,0 +1,13 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ matrix (0.4.2)
+
+PLATFORMS
+ x86_64-darwin-20
+
+DEPENDENCIES
+ matrix
+
+BUNDLED WITH
+ 2.3.3
diff --git a/sample/trick2022/01-tompng/authors.markdown b/sample/trick2022/01-tompng/authors.markdown
new file mode 100644
index 0000000000..26ebe24da6
--- /dev/null
+++ b/sample/trick2022/01-tompng/authors.markdown
@@ -0,0 +1,3 @@
+* Tomoya Ishida (tompng)
+ * tomoyapenguin@gmail.com
+ * cctld: jp
diff --git a/sample/trick2022/01-tompng/entry.rb b/sample/trick2022/01-tompng/entry.rb
new file mode 100644
index 0000000000..97beacc684
--- /dev/null
+++ b/sample/trick2022/01-tompng/entry.rb
@@ -0,0 +1,40 @@
+ eval((s=%~c=(0..35
+ ).map{s[2*_1+1]}*'';class$Inte
+ ger;def$quXinclude(Math ;spXo(a)=self*
+ a.pow(87X=h=32.chr;g=PI/480;ls=(sp*31X,89)%89;
+ def$abX+'eval((s=%'+(n=? .next)+s*88.chr+[nXs()=[a
+ =self%X+'.split(',sp*25+'?'+88.chr+');(0..36).mapX89,89-
+ a].miX{s[2*_1].split}',sp*31+".join.tr('$',$/)))"]*$/)Xn;end
+ ;reqX.split$/;trap(:INT){puts;exit};q=->t,i{a,y=((t+i*99)Xuire
+ 'matrX%960). ivmod(80);[(a*(7+i)+i*23)%79+(y+a)/(5+i%4)%2,39Xix';1
+ 5.tiX-y/2]};p=->t,u{a=->b,c{(0..5).sum{(u%2-1)*E**(t*(b+c*_1)*gXmes{
+ |i,*X.i+ i*u+=5+sin(u*u))}};x,z=a[5,3]. 5,3].rect;x+=y.Xv|z=
+ *?!Xi a[19,4];z+=w;r=(4+(x.abs+z.i).ab };t=(0..959).fX..?
+ W,?Xind{|t|(0..29).all?{x,y=q[t,_1];(x 2||h=ls[y][x]X[,*
+ ?]..X[/[^!-}]/]}};h=($**h+h).chr;eval( []} ->(x,yX?};a
+ =(0X,a,b){x=x*36+39.5;y=19.5-y*18;b*=1 |i|((yX..1
+ 34)X-b).ceil..y+b).map{|j|((x-i)/a+(y j)/ .times{X.ma
+ p{zXx,z=p[t,_1];l=u```=0;while``````(l<1)``; u+```=0 ;d=x-y;X.in
+dex(Xl+=(d.abs+(z-w``)``.i).ab``s*1.``1 ;x``,z=y``,w;o[v``=``x.r d.imag/Xc[i+
+15*Xd.abs*l*sin(2*``l-t``*g*80``-_1) l*(``1-l)/``6,a``=l*( -l)**2*0.X_1]
+)};X7,a*2]&&o[v,z,``0.0``3,l**`` ``times``{|i``|(8+i).times{|Xw=*
+MatXj|o[sin(i)/2+````` ```sin( `/2.0`````````)*j/200,j*0.0Xrix
+[*(X5-1,0.02,0.1]``}} ``. q[t,``_1];m``[y][x]= };i=-X0..
+44).X1;$><<(['%%','[H .map{|j|(0..79).map{|k|x=(Xmap{
+ |i,X -39.5)/35.8;y=( i+=1;m[j][k]?h:c[i]):ls[j]X*b|
+ v<<X[k];}*''}*$/<<0) 1)%9 te"`")#qv.jSaL{=;q(Q}4fXa.z
+ ip(Xjs(:#tK`Jm))FKO /A9(2'%iorvf7 eEa0uV xv+Q@qUU](L@&Py .1v'X0..
+ ).suXydSEH{-GI|-5(,z G5evpq,[b50 D[ t {on,I?VStS`?G@LoqFCXm{|j
+ ,k|Xj1.QnxKz!mH%o# )b2Seut,]! 48 lBieJGi 5jeNPD#b}H3X-(p
+ =(iXaVz#8*+US,hgF 5#6]y-` 4hy HN hF75WjD!0IxJ$sX+k)
+ .powX+UP"cNUE9- G< tHvV;Ib <-s U T ? vlE xylg=x#X(i+k
+ ,88)XV9u$9lKb9 @C do7+-w >l { v9 { P l ga%]AK<e&'X+1)*
+ (j||(X4ifK/6S+ k} @@*a} 6rS xn"Q[M 8 `|g>$#BrjXb<<p;
+ 0))}XtbDp'Kc t2 Dat9C s C rL+ g,j]Tf B< eMI+zzkWX;b}]
+ .lup.XtVP<ak IM E/+)B jwv uB (Twqed D* dyf_dT7Xsolve
+ (v);13Xn:8 #_ RiSTO, [Fk m O]O#"+ a_ cT_.X5.time
+ s{c[i+X e5 T`FBEC q*f 2 o@{a<eUG aW PX15*_1]
+ =z[a[_1]X z_@`nll 7F1 2 [=^uS0z^ 6X||w.shif
+ t]}};eval(Xfg K#R N bp-E_Xc)~.split(
+ ?X);(0..36).map{s[2*_1].split}
+ .join.tr('$',$/)))
diff --git a/sample/trick2022/01-tompng/remarks.markdown b/sample/trick2022/01-tompng/remarks.markdown
new file mode 100644
index 0000000000..70601908b7
--- /dev/null
+++ b/sample/trick2022/01-tompng/remarks.markdown
@@ -0,0 +1,51 @@
+### Remarks
+
+Just run it with no argument:
+
+ ruby entry.rb
+
+Or run it with one non-ascii half-width character argument:
+
+ ruby entry.rb ⬮
+ ruby entry.rb 𓆡
+
+I confirmed the following implementations/platforms:
+
+* ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin19]
+* ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [x86_64-darwin20]
+
+### Description
+
+This program is an aquatic quine.
+Some characters in the code are overwritten with `" "`, but this program can restore the missing parts.
+Every frame of this animation is an executable ruby program that let fishes start swimming again from their current position.
+
+### Internals
+
+#### Error Correction
+
+Error correction is performed for each block of length 135.
+It consists of 89 kinds of characters(`[*('!'..'W'), '[', *(']'..'}')]`) and satisfies the following constraint.
+
+```
+matrix(size: 45x135) * block_vector(size: 135) % 89 == zero_vector(size: 45)
+```
+
+To restore the missing characters in the block, we need to solve a linear equation problem in modulo 89.
+This can be achieved by using bundled gem 'matrix' and overwriting some methods.
+
+```ruby
+require 'matrix'
+matrix = Matrix[[3, 1, 4], [1, 5, 9], [2, 6, 5]]
+class Integer
+ def quo(x) = self * x.pow(87, 89) % 89 # Fermat's little theorem. 89 is a prime number.
+ def abs() = [self % 89, 89 - self % 89].min # To avoid division by multiple of 89.
+end
+answer = matrix.lup.solve([1, 2, 3]) #=> Vector[24, 42, 83]
+(matrix * answer).map { _1 % 89 } #=> Vector[1, 2, 3]
+```
+
+#### Resuming Animation
+
+The entire animation of this fish tank is a loop of 960 frames.
+This program uses position of the floating bubbles to detect current frame number from the executed source code.
diff --git a/sample/trick2022/02-tompng/authors.markdown b/sample/trick2022/02-tompng/authors.markdown
new file mode 100644
index 0000000000..26ebe24da6
--- /dev/null
+++ b/sample/trick2022/02-tompng/authors.markdown
@@ -0,0 +1,3 @@
+* Tomoya Ishida (tompng)
+ * tomoyapenguin@gmail.com
+ * cctld: jp
diff --git a/sample/trick2022/02-tompng/entry.rb b/sample/trick2022/02-tompng/entry.rb
new file mode 100644
index 0000000000..2e2e2bcf74
--- /dev/null
+++ b/sample/trick2022/02-tompng/entry.rb
@@ -0,0 +1,32 @@
+ q=->{!sleep _1/1e2};p=(
+ c=0..2).map{[_1/9r ,0,5**_1.i/3,1,0]}
+ require'socket';puts'op' "en http://localhost:#{(
+ w=TCPServer.new$*[0]||0).addr[1]}";Thread.new{q[2];f=[-1
+ ]*s=3;t=Time.now.to_f;p.select!{0<_1[3]=[_1[3]+_1[4]/8.0,1
+ ].min};9.times{h=p.map{[2**(_1*t.i)/_4**0.5/(1+Math.sin(2*t-
+ 9*_1%2)**32/16),_2+_4*( _3-_2)]};r=[s*3/2,84].min;g=->{x,y=
+(s*(1+_1+1i)/2).rect;x<0 ||x>=s-1||y<0||y>=s-1?0:((l=f[y+1])[
+x+1]*(a=x%1)+(1-a)*l[x] )*(b=y%1)+(1-b)*((l=f[y])[x+1]*a+(1-
+a)*l[x])};f=(1..r).map {|y|(1..r).map{|x|z=1.5+1.5i-3.0*(y
+.i+x)/r;[h.sum{g[_1.*z +_2]}*0.9,1].min}};s=r};c=f.flatten
+redo};loop{s=w.accept ; Thread.new{r=s.gets;h='HTTP/1.1 '+
+"200 OK\r\nContent-" 'T' "ype:text/html\r\n\r\n";r['/ ']?s.
+ <<(h+'<style>ifram' 'e{' 'opacity:0;height:0;}input{wid'+
+ 'th:252px;}</styl' 'e>' '<form target="i"><input src="'+
+ "g#{rand}\" type" '="im' 'age"><iframe name="i"></ifra'+
+ 'me></form>'):r ['/g'] ?(h[/:.+l/]=?:'image/gif';s<<
+ h+'GIF8' '7a'+[84,
+ 84,246,0,*(0..383).map {15*_1. /(383r)**(3-_1%
+ 3)*17}].pack('v3c*'); loop{ s<<[67434785,5,
+ 44,84,84,7,c.map{_1* 127} .each_slice(126
+ ).map{[127,128,*_1 ] .pack'c*'}*'',
+ 1,129].pack('V3x' 'v2na*c2x');q[
+ 5];q.[]1while(r ==r=c)}):(x,y,
+ z=r.scan(/\d+/).map{_1.to_f/
+ 126-1};z&&p<<[rand-0.5,(
+ z=x+y.i)*1.5,z/(z.
+ abs+0.9),0,-p[
+ -3][4]=-1]
+ s.<<h);s
+ .close
+ }}
diff --git a/sample/trick2022/02-tompng/remarks.markdown b/sample/trick2022/02-tompng/remarks.markdown
new file mode 100644
index 0000000000..3b2d3fd84b
--- /dev/null
+++ b/sample/trick2022/02-tompng/remarks.markdown
@@ -0,0 +1,32 @@
+### Remarks
+
+1. Run it with `ruby entry.rb 8080`
+
+2. Open "http://localhost:8080"
+
+3. Click on the screen and interact with it
+
+I confirmed the following implementations/platforms:
+
+* Ruby Version
+ * ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [x86_64-darwin20]
+* Browser
+ * Chrome(macOS, Android)
+ * Firefox(macOS)
+ * Edge(macOS)
+
+### Description
+
+This program is an HTTP server that provides a fractal creature playground.
+You can see the heartbeat of a mysterious fractal creature. Clicking on the screen will change the shape of the creature.
+Surprisingly, this interactive webpage is built without JavaScript.
+
+### Internals
+
+Fractal: Iterated function system
+Rendering from server: Streaming animated GIF
+Sending click event to server: `<input type="image" src="streaming.gif">` with `<form target="invisible_iframe">`
+
+### Limitations
+
+Does not work on Safari and iOS.
diff --git a/sample/trick2022/03-mame/authors.markdown b/sample/trick2022/03-mame/authors.markdown
new file mode 100644
index 0000000000..0e420fdf5d
--- /dev/null
+++ b/sample/trick2022/03-mame/authors.markdown
@@ -0,0 +1,3 @@
+* Yusuke Endoh
+ * mame@ruby-lang.org
+ * cctld: jp
diff --git a/sample/trick2022/03-mame/entry.rb b/sample/trick2022/03-mame/entry.rb
new file mode 100644
index 0000000000..f24595dfa9
--- /dev/null
+++ b/sample/trick2022/03-mame/entry.rb
@@ -0,0 +1,27 @@
+2022;"#
+
+.chars} {puts'TRICK+2022'
+ \ { ;
+#';$><< b
+ ?!
+};#{s=' ' # 0
+! s[0]? ( b=$<.read ;'
+} ub( ,''}
+';a= ''<<32
+b.lines {puts( ?.. *(
+b.size) .gsub(/./) {
+b.sub!( /^#$`\K(\S)
+ /x,a)?$1:a }
+ .rstrip)}):
+ ( [ 12,1,12,11].
+cycle { | i | t = ( s *
+
+10<<
+10)*
+10+ %(\e[A)*
+10
+10. times{t[i*
+ _1 ] = 'TRICK+2022'[
+ _1 ] };$><<t
+ sleep 1})
+ }"
diff --git a/sample/trick2022/03-mame/remarks.markdown b/sample/trick2022/03-mame/remarks.markdown
new file mode 100644
index 0000000000..c38279f016
--- /dev/null
+++ b/sample/trick2022/03-mame/remarks.markdown
@@ -0,0 +1,96 @@
+Execute the program normally.
+
+```
+$ ruby entry.rb
+```
+
+It shakes a string.
+
+... Wait! This is not all.
+
+Next, please apply "leftward gravity" to each letter in the file.
+IOW, if there is a space to the left of a letter, move it to the left.
+Here, you may want to use the following command.
+
+```
+$ sed "s/ //g" entry.rb | tee up.rb
+```
+
+This program applies "upward gravity" to each letter in an input text.
+The following demo will help you understand what this means.
+
+```
+$ cat test.txt
+$ ruby up.rb test.txt
+```
+
+Now, here's where we come in.
+Please apply "upward gravity" to entry.rb.
+
+```
+$ ruby up.rb entry.rb | tee left.rb
+```
+
+I think that you already noticed that.
+This program applies "leftward gravity" to an input text.
+
+```
+$ cat test.txt
+$ ruby left.rb test.txt
+```
+
+`sed` is no longer required to create `up.rb`; just use `left.rb`.
+
+```
+$ ruby left.rb entry.rb > up.rb
+```
+
+We've come to the final stage.
+Please apply `left.rb` to `left.rb`.
+
+```
+$ ruby left.rb left.rb | tee horizontal.rb
+$ ruby horizontal.rb
+```
+
+Of course, it is also possible to apply `up.rb` to `up.rb`.
+
+```
+$ ruby up.rb up.rb | tee vertical.rb
+$ ruby vertical.rb
+```
+
+Can you tell how they work? Enjoy analyzing!
+
+
+
+---
+Code reading tips (spoiler)
+
+Some code fragments are highly reused between the programs.
+For example, note that this program has one code fragment to input a text
+(`b=$>.read`); `up.rb` and `left.rb` share and use this code fragment.
+Also, `horizontal.rb` and `vertical.rb` share the fragment `puts'TRICK+2022'`.
+Sometimes letters in very distant places are reused all over the place.
+
+Can you tell how it detects if it is already aligned or not yet?
+Here is a simplified version of the gimmick to switch behavior when
+left-aligned:
+
+```
+"\ #{puts('not left-aligned yet')}
+ # {puts('left-aligned')}"
+```
+
+And for top-aligned:
+
+```
+"#
+xx{puts('top-aligned')}
+x#{puts('not top-aligned yet')}
+"
+```
+
+It is also necessary to detect "top-left-aligned" and "left-top-aligned".
+I made tons of subtle adjustments and trial-and-error to create the program.
+I no longer know precisely how it works.
diff --git a/sample/trick2022/03-mame/test.txt b/sample/trick2022/03-mame/test.txt
new file mode 100644
index 0000000000..18802153a9
--- /dev/null
+++ b/sample/trick2022/03-mame/test.txt
@@ -0,0 +1,13 @@
+T
+ R
+ I
+ C
+ K
+ |
+ |
+ |
+ |
+ 2
+ 0
+ 2
+ 2
diff --git a/sample/trick2022/README.md b/sample/trick2022/README.md
new file mode 100644
index 0000000000..3b2af6f86b
--- /dev/null
+++ b/sample/trick2022/README.md
@@ -0,0 +1,14 @@
+This directory contains the award-winning entries of
+the 4th Transcendental Ruby Imbroglio Contest for rubyKaigi (TRICK 2022).
+
+THESE ARE BAD EXAMPLES! You must NOT use them as a sample code.
+
+* 01-tompng/entry.rb: "Best fishbowl" -- Tomoya Ishida (tompng)
+* 02-tompng/entry.rb: "Most interactive code" -- Tomoya Ishida (tompng)
+* 03-mame/entry.rb: "Most anti-gravity" -- Yusuke Endoh
+
+These files are licensed under MIT license.
+
+For the contest outline and other winning entries, see:
+
+https://github.com/tric/trick2022
diff --git a/sample/trick2025/01-omoikane/authors.markdown b/sample/trick2025/01-omoikane/authors.markdown
new file mode 100644
index 0000000000..5c6823c077
--- /dev/null
+++ b/sample/trick2025/01-omoikane/authors.markdown
@@ -0,0 +1,5 @@
+* Don Yang
+ * omoikane@uguu.org
+ * cctld: us
+ * bsky.app/profile/omoikane.bsky.social
+ * twitter.com/uguu_org
diff --git a/sample/trick2025/01-omoikane/bf.rb b/sample/trick2025/01-omoikane/bf.rb
new file mode 100644
index 0000000000..74f5abe7e4
--- /dev/null
+++ b/sample/trick2025/01-omoikane/bf.rb
@@ -0,0 +1,81 @@
+#!/usr/bin/ruby -w
+# Simple BF interpretor.
+#
+# This works by translating input code into ruby and evaluating the
+# translated ruby code. Doing it this way runs much faster than
+# interpreting BF on our own.
+#
+# There is no error reporting whatsoever. A malformed input may result in
+# a syntax error at run time, but good luck in finding where it came from.
+
+
+# Setup empty tape and initial pointer position. Note that tape size is
+# fixed. We can make it infinite by initializing it to "[]" here and
+# adding some nil checks in the generated code, but avoiding those checks
+# makes the program run ~10% faster.
+$code = "t=Array.new(30000,0); p=0;"
+
+# Counters for pending add or shift operations. We buffer incoming +-<>
+# operators and output a single merged operation when we encounter a
+# different operator.
+$buffered_add = 0
+$buffered_shift = 0
+
+# Flush pending add operations, if any.
+def flush_add
+ if $buffered_add != 0
+ $code += "t[p]+=#{$buffered_add};"
+ $buffered_add = 0
+ end
+end
+
+# Flush pending shift operations, if any.
+def flush_shift
+ if $buffered_shift != 0
+ $code += "p+=#{$buffered_shift};"
+ $buffered_shift = 0
+ end
+end
+
+def flush_pending_ops
+ flush_add
+ flush_shift
+end
+
+# Convert input characters to ruby.
+ARGF.each_char{|c|
+ case c
+ when '+'
+ flush_shift
+ $buffered_add += 1
+ when '-'
+ flush_shift
+ $buffered_add -= 1
+ when '<'
+ flush_add
+ $buffered_shift -= 1
+ when '>'
+ flush_add
+ $buffered_shift += 1
+ when ','
+ flush_pending_ops
+ $code += "if c=STDIN.getc;" +
+ "t[p]=c.ord;" +
+ "else;" +
+ "t[p]=-1;" + # EOF is interpreted as -1.
+ "end;"
+ when '.'
+ flush_pending_ops
+ $code += "print t[p].chr;"
+ when '['
+ flush_pending_ops
+ $code += "while t[p]!=0;"
+ when ']'
+ flush_pending_ops
+ $code += "end;"
+ end
+}
+flush_pending_ops
+
+# Evaluate converted code.
+eval $code
diff --git a/sample/trick2025/01-omoikane/entry.rb b/sample/trick2025/01-omoikane/entry.rb
new file mode 100644
index 0000000000..c84f8079ae
--- /dev/null
+++ b/sample/trick2025/01-omoikane/entry.rb
@@ -0,0 +1,32 @@
+ a=+Math::PI/13
+ #Z---z';#za-mRUBY
+ #A-ZaA-Mn--\[+>+>++
+ '"N-Z(\++\[->++++@"
+ b=\[->+> +>+>\[h_
+ p%{} eact
+ zoraq ;%{ GF. rin);
+ %{eb} r A R p *""\]
+ <<<{{{ }<\]<b
+ ]<l(%w| } ; a;a=%Y/
+ evar{|c)} <][ #pgny\W{f
+ chaa,b)]>++[ ->+>>>>>[40v
+ .tr(= ' ;eval(%w{r=u=b= y =0;%{
+ (ct;c ) ; ] <<->--<<< < < ] >>[>,
+ exi}; a * = A RGV.siz e > 0 ? -1:1;
+ z=[] ; A R G F .ea c h _ l i n e{|i
+|i.eac h _ g r aph e m e _ c l u ster
+{|j|i f ( k = j.o r d ) < 3 3 ; r+=k<
+32?k==9? 8 - r%8 : k = = 1 0 | |k==13
+?[u+=1,-r][ 1]: 0 : 1 ; e lse;z+=[[u,
+r,j]];b+=r;y+=u;r+=1;end;}};if(s=z.si
+ze)>0;b/=s;y/=s;m,n=z[0];i=Math::tan(
+a/2);j=Math::sin(a);z.map!{|d|p=d[1]-
+b;q=d[0]-y;p-=(i*q).round;m=[m,q+=(j*
+ p).round].min;n=[n,p-=(i*q).round].
+ min;[q,p,d[2]]};r=n;u=m;z.sort.eac
+ h{|d|p,b=d;r=(u<p)?n:r;print"\n"
+ *(p-u),"\40"*(b-r),d[2];u=p;r=
+ b+1};print"\n";end}*"");%(]>
+ "tyvuts(}}.--.>--.>+.<++'
+ )b\40"gena.(c)2025<<<
+ #)#ehol""+a*.^_^
diff --git a/sample/trick2025/01-omoikane/remarks.markdown b/sample/trick2025/01-omoikane/remarks.markdown
new file mode 100644
index 0000000000..2aa77d64e4
--- /dev/null
+++ b/sample/trick2025/01-omoikane/remarks.markdown
@@ -0,0 +1,71 @@
+### Summary
+
+This is a rot13 filter. Given an input text, it will **rotate** the text by **pi/13** radians. Two modes of operation are available, selected based on number of command line arguments.
+
+Rotate clockwise:
+
+ ruby entry.rb < input.txt
+
+Rotate counterclockwise:
+
+ ruby entry.rb input.txt
+ ruby entry.rb - < input.txt
+
+### Details
+
+This program interprets input as an ASCII art with each character representing individual square pixels, and produces a rotated image to stdout. All non-whitespace characters are preserved in output, only the positions of those characters are adjusted. While all the characters are preserved, the words and sentences will not be as readable in their newly rotated form. This makes the program suitable for obfuscating text.
+
+ ruby entry.rb original.txt > rotated.txt
+ ruby entry.rb < rotated.txt > unrotated.txt
+
+But note that while `unrotated.txt` is often the same as `original.txt`, there is no hard guarantee due to integer rounding intricacies. Whether the original text can be recovered depends a lot on its shape, be sure to check that the output is reversible if you are using this rot13 filter to post spoilers and such.
+
+Reversibility does hold for `entry.rb`:
+
+ ruby entry.rb entry.rb | ruby entry.rb | diff entry.rb -
+ ruby entry.rb < entry.rb | ruby entry.rb - | diff entry.rb -
+
+Also, there is a bit of text embedded in the rotated version:
+
+ ruby entry.rb entry.rb | ruby
+
+But this text is encrypted! No problem, just rotate `entry.rb` the other way for the decryption tool:
+
+ ruby entry.rb < entry.rb > caesar_cipher_shift_13.rb
+ ruby entry.rb entry.rb | ruby | ruby caesar_cipher_shift_13.rb
+
+If current shell is `bash` or `zsh`, this can be done all in one line:
+
+ ruby entry.rb entry.rb | ruby | ruby <(ruby entry.rb < entry.rb)
+
+### Miscellaneous features
+
+To rotate to a different angle, edit the first line of `entry.rb`. Angles between -pi/2 and pi/2 will work best, anything outside that range produces more distortion than rotation, although the output might still be reversible.
+
+Setting angle to zero makes this program a filter that expands tabs, trim whitespaces, and canonicalize end-of-line sequences.
+
+This program preserves non-ASCII characters since input is tokenized with `each_grapheme_cluster`, although all characters that's not an ASCII space/tab/newline are given the same treatment. For example, the full-width space character (U+3000) will be transformed as if it's a half-width non-whitespace ASCII character.
+
+If input contains only whitespace characters, output will be empty.
+
+The layout is meant to resemble a daruma doll. There was still ~119 bytes of space left after fitting in 3 ruby programs, so I embedded a brainfuck program as well.
+
+ ruby bf.rb entry.rb
+
+A `sample_input.txt` has been included for testing. After rotating this file 26 times either clockwise or counterclockwise, you should get back the original `sample_input.txt`.
+
+ ruby entry.rb < sample_input.txt | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | diff sample_input.txt -
+ ruby entry.rb sample_input.txt | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | diff sample_input.txt -
+
+Additional development notes can be found in `spoiler_rot13.txt` (rotate clockwise to decode).
+
+ ruby entry.rb < spoiler_rot13.txt
+
+### Compatibility
+
+Program has been verified to work under these environments:
+
+ * ruby 3.2.2 on cygwin.
+ * ruby 2.5.1p57 on linux.
+ * ruby 2.7.4p191 on linux.
+ * ruby 2.7.1p83 on jslinux.
diff --git a/sample/trick2025/01-omoikane/sample_input.txt b/sample/trick2025/01-omoikane/sample_input.txt
new file mode 100644
index 0000000000..244530f265
--- /dev/null
+++ b/sample/trick2025/01-omoikane/sample_input.txt
@@ -0,0 +1,35 @@
+ T U
+ S V
+
+ R T U W
+ S V
+
+ Q R W X
+
+ Q X
+ P i h g f Y
+ j e
+ P k d Y
+
+ O l c Z
+ O Z
+ m b
+
+* N N n + a A A *
+
+ o z
+ M B
+ M p y B
+
+ L q x C
+ r w
+ L s t u v C
+ K D
+
+ K J E D
+
+ I F
+ J H G E
+
+ I F
+ H G
diff --git a/sample/trick2025/01-omoikane/spoiler_rot13.txt b/sample/trick2025/01-omoikane/spoiler_rot13.txt
new file mode 100644
index 0000000000..91636176b8
--- /dev/null
+++ b/sample/trick2025/01-omoikane/spoiler_rot13.txt
@@ -0,0 +1,470 @@
+ .
+ text
+ ted t to
+ rota tex
+ dit HTML
+ to etes oss
+ sier wri acr
+ t earb"), ions .
+ ke itry. etat text
+ o ma "en erpr tive
+ ge te.g. e int: erna
+ L paut ( tiplsteps alt edit,he
+ a HTM inp muling cted ach dit tu
+ -w tes nt as havellow expe er ely ere yo
+ uby neragume can e fo the aftrect whethis
+ in/rt gee ar hat y th t. has stepindicesshat
+ usr/bcripingl ext tt tr texsult ion to prois w
+#!/his s a s of t migh inale re rotatededis aich ts.
+# TTakest. ece you origf th tra ts neike , wh tex
+ # stdou a piles, the ck i e exemenuld lusly ated the
+ # ite ang s tod che f th movu wotaneo rot pen
+ # To wrrent edit, an se orsort yoimul and nd o ne.
+ # diffe ome tion1-2. ecaue cu Whats s inal t, a en do
+ # ke srotaeps ous be thve. tex orig ayou t wh
+ # 1. Maply t st tediecausuitiated hold he l tex this
+ # 2. Apepea is lt bunint rot to rom ted. ated but
+ # 3. R cessficu is l and ough le fenabl upd nce, in
+ # pro diftextgina e en L fiipt the atie dable
+ # Thisalsoive ori larg HTMascr paste of p reay
+ # and rnat thedes: at's te a jav opy& bit its. t is Rubke },
+ # alteeditrovi t th nerawith en c fair l ed thar ine-li, %w{
+ # can pt p ayou to geser , th h a manua textasiequot %()
+ # scri a l ipt brow page witose ing 's eple %{},
+ # Make scrin a TML textn th writt itulti of ter
+ ## 1. thisTML the H dit ly o lly:l, buas m use Ras t
+ # Run ut H via ly euick ficaiviauby hakestes. eral wan
+ # 2. outp its anualte q peciy trse R.rb m quo Gen nd we
+ # y ed to mitera by sactlecauntryouble for rs a
+ # Appl eed you g Rut exs, b. ele+d ithm acte
+ # 3. ll nlet ardins nouageientsing Algor char paperpplyg
+ # stiill regons ilangnvenmon ast ces: are nal ply ardin
+ # Youol w hingtatither e co com "A Feren els rigi sim regato
+ # to re trienny o quit the on diff r pix . O andailsnter
+ # e mole oo ma areourse asedtwo e ous. tionates detn ce o
+ # Onltiped tthatof c is bith sincalue rotardine toatio is n
+ # mumparors and ithm h, w ls, er v r of coot du rot here ns d
+ # coerat//, lgor Paet pixeract enteinput, but to r, tratio, an.
+ # op{}, on aAlan ing cha ng cthe as isspecion. ente opeinput two
+ # %W tati by blendinal ardiing ues th reunct on ctionthe ne or
+ # e roion" for orig reghift vale witer f tatirota of a li
+ # Thotat ort the tionut snate car_cen e roise hapeextr
+ # R supperve idera aboordixtra get stablockwhe s an ons.
+ # No pres consthingd coed e see ore terclon tting tatiugh
+ # - to nal any-basee neble, a mcoun lot nser e roltho
+ # itio sayto 0ng, wersi tingise/ds a by i oducd, a
+ # Addsn'trms undit rev elecockwepenible ] prstea
+ # - doensfor routpu in se clIt dvers pi/2t in ly to
+ # trategehe o care utivt. e re i/2, tex ical
+ # inke t tra onsecr ou mad [-pt the omat
+ # ma h exat c othen be weenstorible. aut
+ # wite theachon ca beto divers sted
+ # Evenantecel tati glesnd te re adju s.
+ # guar cane ro y ane tell b l be ment
+ # willn th Onlrang sti wil ele
+ # ofte gle.that ight idth text
+ # n anide ion m . W ble erialink
+ atiooutsrmat/ 13 entss. edita les. he scan l
+ Rotles nsfo:PI elemcell all tup . T we
+ # Ang traath: edit ter to eme) textthat
+ # the = M of harac ched graph ate uch her.
+ #NGLE ightre c.9em" atta al, rotD, sh ot
+ A e hesqua= "0 be seri me toue I eac
+ Linure GHT me to x, aphe uniqs to
+ # ens_HEI s na (y, d grme aation
+ #LINE clas "t" t of s anaphe rot
+ yle SS = a lis nateh grrent
+ # St_CLA as ordi eaciffe
+ EDIT nput he cogivess d
+ ad i ed td to acro
+ # Lo y neaddeheme
+ # onl is grap 0
+ # Wemberame put _y = {|c|
+ # nuhe sd_in] ursor ster
+ # t loa = [ = c ine|_clu 8
+ defdataor_x 0 ne{|lheme x %
+ cursal =h_li_grap 1 sor_r\n" ]
+ seri.eaceach= " "x +=" cur= "\ , c]
+ ARGFine. c =rsor_ "\t 8 - c = rial
+ l if cu c ==x +=" || x, se
+ lsifrsor_ "\n0 sor_
+ e cu c ==x = 1 cur
+ lsifrsor_y += r_y, t
+ e cursor_ urso thay
+ cu [[c= 1 ilityed bext.
+ lse ta +=_x +1 obabollowal t
+ e daursor += e pron frigin
+ cerial ass. s thtatihe o
+ s of m easee roin t l be hat
+ end nter incrkwislts wilges thave
+ m ce nter clocresu heret ed We
+ } a fro n cee. a sa) o, taighion.
+ dat nter atio, i.e ver zer strotat
+ } turn n ce rotible vic frome.g.he r ,
+ re tatio s asvers (or away er, er t tione.
+ nd e ro mase retion und cent aftcts: rotaitiv
+ e mput er ofll brota e rotionld betifa o. ox. ftern pos
+ # Co centon wiise ow wrotashouse ar zerng box aemai r
+ # ing tatilockw to hthe hey the d ofunding bon r othey
+ # Use roterc due ear an tduce nsteaf bounditati s atbilittion
+ # thcoun ely, ts nd tho re ty iter of bor ro factersiul op
+ # a unattifacaggegs t fini cenner oafte arti revusef f
+ # forte arore jthin e ino be cor and get theost er or
+ # Unsiblut mious itivon to before we losehe m centr fo
+ # vime o var postation ts be thatlso be t theedito
+ # coried owardf rotatinate e is we a to ause an and the t
+ # t nd tter of roordi thes andpears ll catesaddsm in tha
+ # Rou center ol co of ter,s ap s wienerrts rithd for
+ # - Set cenat al all cen mas cterly guppoalgo neer).
+ # - Seth th with ther of charat onso sion reatithe
+ # - suc ened d ofente. ing script alotat a gol e
+ # happnsteang cacts emovhis r thahe re iss to
+ # hat es i Usirtif nd rhy tditoent tther thi
+ # Wplacure.the a ng ais wan eplemsure for
+ # featite ertiich ave reimnot need
+ # desp t ins, whTo h to am any
+ # thashiftt. need. Ie is
+ # Note to g texill riptther
+ # massacin we wvascure
+ # repltes,ed jaot sa)
+ # deleerat am n(dat ze
+ # genl (Ienter ta.si
+ # tooet_cy = 0t| / da
+ #ef g = cach{|1] cy
+ d cxta.e+= t[0] ize,
+ da cx += t[ ta.s es.
+ cy / da inat
+ n cx oorda)
+ } etur to ccy, .
+ r ion cx, 2) gain
+ end rotatta, (a / X a
+ ply te(da:tan(a) | r in
+ # AprotaMath::sinp{|tnts. shea
+ def x = Math:a.maonte then
+ ry = n dater c cx Y,
+ retur Cent1] - cy r in me).
+ r # = t[0] - shead aphe eme.
+ x = t[ X, round , gr graph
+ y r in y).round erial ach
+ Shearx * x).roun x, s nd e
+ # -= (ry * y). (y, arou
+ x += (rx * ted ] pan
+ y -= ( updat[3] ne s
+ x urn 2], ith o
+ # Ret, t[ xt wfix)
+ [y, x L te_pre
+ HTM, id
+ } k ofdata0] n
+ d blocock(ata[ ].min
+ en rate e_bl = d t[1]].mi
+ Geneneratin_xt| _x, t[0]
+ # f ge_y, mch{|[min_y,
+ de minta.eax = [min >\n"
+ da min_y = ix}\"
+ min_ x pref
+ min_y {id_
+ } x = min_=\"# r_y)
+ rsor_y = e id{|t| curso
+ cursor_"<preach y -
+ cuxt = ort.t < y * (
+ teata.sx = or_y"\n"
+ d y, curs += = yin_x
+ if textor_y = m
+ cursor_x
+ curs [3] &" "
+ = t== "amp;"
+ end textext = "&= "<
+ ner_er_text xt =lt;"" ' +
+ in inner_tr_te= "&= "> '">
+ if inninneext xt =gt;" SS +_s +
+ sif er_tr_te= "& x) +_CLA].to
+ el inninneext rsor_EDIT t[2
+ sif er_t - cu"' + ix +
+ el inn (x ass=_pref
+ d " *n cl+ id low.
+ en += "<spa="' t + er be
+ ext '" id_tex numb
+ t 'nneran>" ial ns.
+ i</sp+ 1 ser colum
+ "= x re>" next. by
+ r_x n</p the airs them
+ urso + "\ find er p oup
+ c ext er, numbta) d gr
+ } rn t numbrialap(das an
+ retu ial f sewn_my row
+ nd serst or_dors b
+ e eacha liursoumbe
+ For rns te_cal n ]]
+ # Retuneraseri} |t| ] [t[2
+ #ef geort = {ach{t[1]] += ]
+ d # Sumnsrt.emns[t[1] [t[2]
+ cola.socolumns[ ] = n.
+ dat if colu t[1] olum 0]]) .
+ e mns[ ch c [r[ ight
+ elscolu or ea 1] + he r by
+ rs f e - to t sortnext
+ end umbe .siz mber we the
+ al n r| [1, r l nu o if us
+ } seri [] |_, ip(r eria s, s get
+ Add ls =ach{ r.z xt s inateould )
+ # erians.es += e ners. oordhat w [0]]
+ solumrial s d th pai n) c1, t ials
+ c se rial , finmberta) olum by [ser a
+ n se mberal nup(daw, cials 1] + extr
+ }etur l nuseriht_ma (ro ser e - one
+ r eria of _rig with all .siz get
+ end ch slistrsortartotate [2]}ials . e we ,'
+ r eas a e_cues snd r t| t ser airs sinc + '"
+ # Foturnerattuples a. map{|s[1, ue p) ine, o_s
+ # Re genput tuplbersort.erial valairsnewl 1].t
+ def# Input numta.sip(s keyal_ping + t[
+ # inrial= dals.z s asserirail efix
+ # seals eria pairix, ut t + pr
+ serirn s mber(prefitho "'
+ retu l nu_mapies wate. '":
+ eriarsorentrtempl|t| _s +
+ end at st_cumap the .map{].to
+ Formnverate rom airs+ t[0
+ # f coenerne fal_pfix
+ de # Gewliseri pre es.
+ # nurn "' + valu
+ ret' " nate
+ "\n ordi
+ } * f co) a[0]
+ d ge odata dat
+ en ranize(_x =
+ Getet_s minn_x
+ #ef gn_y,= min_y min 1
+ d mix_x = mi|t| , x].max y +
+ max_y ach{t in_x, x].min min_
+ mata.ex = = [max_x, y].max y -
+ da y, n_x = [min_y, y]. max_
+ mix_x = [max_y 1,
+ man_y = [m n_x +
+ mix_y - mi
+ ma x_x
+ n ma
+ }etur
+ r ut
+ end _inp
+ loadty? ) a) GLE)) /td>
+ a = .emp (data(dat -ANNGLE ")}< >
+ datdatarn nter_size cy,y, A d> r> , "Ltd> }</td
+ if retu t_ce get cx,x, c /hea "><tdata)}</"R")
+ = geht = data,a, c le>< ng="4eft_ "M"ta,
+ end cy heig ate(e(dat /tit addiock(lata,t_da
+ cx,th, rototat est< ellpe_block(drigh
+ wid ta = = r te t 1" cerate_bllock(
+ t_dadata >Rota ng="{generatte_b l>
+ lefght_ OT" itle pacip">#{gennera labe
+ ri <<"Ed><t cells="top">##{ge le)</
+ int <hea "1" align="toop"> "> togg or
+ prtml> der=t" valignn="t edit to l> errght,
+ <hody> bor"left" vvalig id="(ESC"><u izes-hei
+ <bableign="lefft" ox" dit nonet. minimline
+ <td align=="le heckble elay: tex hat sing
+ <td allignble>e="c>Enabdisplace . ne tcreap.
+ <ttd a</ta typdit"yle=" repor. anel he oy deerla
+ </tr>nputr="e" sters =cursct p ep tis bo ov
+ <p><il fohelpractmove sele nd keo thes t
+ <labeid=" chas = ab = s, also d lin
+ <div SCII keyft+to. "> aluean ae the ;
+ <li>Arrow shi und riptng vWe ccaus ght)
+ <li>Aab /+Z = vascpacio. ill tHei
+ <li>TCtrliv> xt/jaer-sratich wM");; offse
+ <<li>></d ="te lettect o muId("HT}" / p.
+ </ul typerentd aspt tontByHEIG dth
+ ipt iffesireg thalemeINE_ etWi
+ <scrry de deasin.getE"#{L 2) offs
+ // To thecrementht = 0.0 - p.
+ // tut ddocuHeig x += em";ght}
+ // bp = line= 0; 2; .0; + "{hei
+ var yle.t_x or =x < 2 = x / #
+ p.st bes_err 0; cingdth}
+ var min x = erSpa#{wi
+ var(var lett.abs( )
+ for yle.Mathr > e
+ { p.ste = erro ; ;
+ var min_ r = e"em"
+ if( erro x + t_x;); }";
+ { min__x = bes("L"IGHT
+ best ng =ByIdE_HE
+ Spaciment{LINt_x;"); T}";
+ } tteretEle= "# besd("REIGH
+ e.lent.gight ng =tByINE_H;
+ } stylcumeneHeSpaciemen#{LIst_x
+ p.= doe.littergetEl = "= be
+ p style.leent.eighting
+ p.stylocumineHrSpac ta))}
+ p. = dle.lette e; t_da }
+ p.style.l tate.fals . (lefa))}ata))
+ p.sty le sit = tion ns. _map(datht_d
+ p itabe_ed posi itio down_map(rig
+ / Wrnabl rsor ; pos rsor_down_map )}
+ /ar e t cu "M0" rsor e_cursor_down data)
+ v rrenor = t cu erate_cursor_ eft_)} ))}
+ / Cucurs o nex generate_cu ap(lata)_data
+ /var ng t "L", generat ht_map(dight
+ appi = map("M", gen _right_map(r
+ // Mdown rsor_map("R", ursor_right_m
+ var t_cursor_map( te_cursor_rig
+ { nvert_cursor_ nerate_cursor
+ #{convert_cu , generate_c
+ #{conver ("L", genera rs.
+ #{co ht = _map("M", ge ) pai
+ }; rig ursor_map("R" text
+ var rt_cursor_map nal
+ { onvert_cursor rigi
+ #{convert_c x, o n))
+ #{conve uffi . (dow
+ #{c (id s []; ions tries
+ }; of ist = osit t.en )
+ Listdo_l or p bjec ght)
+ // r un curs of O s(ri
+ va erse}; ue] ntrie
+ Rev = { {}; val ct.e
+ //r upft =[key, Obje
+ var lenst key; of
+ var(co e] = lue]
+ fo valu , va on.
+ { up[ [key ey; siti
+ onst = k e po ;
+ }or(c alue] . e sam tyle;
+ f ft[v okes$/; t th = style;
+ { le ystr!-~] rs a tyle = style
+ ed ke /^[ actele) x).style = s
+ } cepteys = char sty suffix).style
+ / AcditK for (id, (1);" + suffix).s
+ /ar e tyle tyle bstrd("L" + suffi
+ v et s setS d.sutById("M" +
+ // Stion = iementById("R .
+ func uffixetElementByI tion
+ { ar sent.getElemen posi
+ vocument.getEl n. sor
+ document.g itio s cur . 0";
+ docum posd) viou tion ff808
+ d rsoror(i pre posi nd:# ;
+ } te cuCurs t at rsor ); grou xt])
+ Updan set ligh""); w cu f80"back erTe
+ // ctio highor, t ne :#80f = " .inn
+ fun lear curs ht a oundstyle ion. fix)
+ { // Ctyle( hlig ckgrid). osit suf
+ setS hig "bayId( me p "M" +t;
+ pdate id;sor,entB at sa yId(= text;
+ // Usor =(curElem ers entBext = text;
+ curStyle.get ractxt) ElemnerText = tex
+ setument cha, te .get).innerText
+ doc fort(id 1); umentffix).innerT
+ texteTex str( doc + suffix).in
+ } lace plac .subfix,("L" + suffix
+ Repon re = id[sufById("M" + su
+ //ncti fix ush(mentById("R"
+ fu r sufst.ptElementById
+ { vado_lit.getElement
+ uncument.getEle
+ document.ge it. [1];
+ documen t ed ) ntry[1];
+ do ecen = 0 t = entry[1];
+ st r() th = rText = entry
+ } do moundo leng innerText = e
+ / Untion ist. ); ix).innerTex
+ /func do_l pop( suffix).inne
+ { f( un ist. L" + suffix).
+ i urn; do_l[0];Id("M" + suff
+ { ret = unntryntById("R" +
+ try = elementById("
+ }ar enffixgetElementBy x);
+ var suent.getEleme suffi
+ vdocument.getEit ) ] +
+ document.e_ed or[0
+ documnabl curs ";
+ if( e sor( line
+ { tCur "in
+ se us. lay =
+ } statt() it; disp
+ dit _edi e_ed yle. ;
+ } ge eggle nabl ).st one"
+ Chann to = !e) elp" = "n
+ //nctio dit dit ; Id("h play ;
+ fu le_ele_e sor)ntBy .dis edit
+ { enabenab (curleme tyle able_ )
+ if( rsorgetE ").s = en S}")
+ { etCuent. ; help ked CLAS
+ socum "")yId(" chec DIT_
+ d sor,entB t"). ("#{E
+ } e (curElem ("edi Name
+ els tyle.get ById lass
+ { setSment ment sByC {
+ docu tEle ment =>
+ t.ge s. etEle ent)
+ } umen enernt.g (ev
+ doc listcume ick",
+ ent f do ("cl
+ } d ev t o ener ) => {
+ // Adonst Listedit nt) ) )
+ for(c ventble_ id); (eve "Z"
+ { addE ena r(t. n", y ==
+ t. if( urso ydow t.ke
+ { setC r("ke even
+ tene ||
+ } tLis) e" ) = "z"
+ ); Evendit Escap ey =
+ } .addle_e == " nt.k ) )
+ } mentenab key (eve "Z"
+ docuf( ! ent. (); && y ==
+ i ( ev edit rlKey t.ke
+ { if gle_ t.ct even
+ { tog even " ||
+ if( = "z
+ }lse ; ey =
+ e do() nt.k
+ { un (eve
+ n; y && s) )
+ }etur rlKe tKey
+ r t.ct (edi );
+ } even match .key
+ if( (); key. vent
+ { undo ent. or, er]); )
+ ( ev curscurso wUp" e" )
+ } e if ext(ght[ Arro spac
+ els aceTr(ri == " Back
+ { replurso .key ); n" ) == "
+ setC vent rsor] wDow key
+ f( e p[cu Arro vent. )
+ } se i or(u == " || e " "
+ el Curs .key r]); ft" ==
+ { set vent curso owLe .key
+ f( e own[ "Arr event
+ } se i or(d y == ; || M"}
+ el Curs t.ke or]) ght" ": "L"};
+ { set even [curs owRi , "R": "
+ if( left "Arr "L", "R
+ } lse sor( y == ); "M": "R"
+ e tCur t.ke sor] "R", "M":;
+ { se even t[cur b" ) L": "M", r(1)
+ if( righ "Ta ? {"L": subst
+ }lse sor( ey == Key : {"sor.
+ e tCur nt.k hift cur {
+ { se eve ent.s ]] + ) =>
+ if( = ev or[0 vent
+ }else ext [curs " ) , (e
+ { ar n nextsor); cape ick"
+ v r = (cur "Es ("cl
+ ursorsor ey == ener
+ cetCu nt.k tList
+ s eve ); Even
+ } if( dit( (); .add
+ else le_e fault it")
+ { togg ntDe ("ed
+ reve tById
+ } nt.p emen
+ eve etEl();
+ ; nt.gedit
+ })cumegle_
+ do tog
+ ; pt> >
+ })scri html
+ </ y></
+ /bod
+ <OT
+ E
diff --git a/sample/trick2025/02-mame/authors.markdown b/sample/trick2025/02-mame/authors.markdown
new file mode 100644
index 0000000000..0e420fdf5d
--- /dev/null
+++ b/sample/trick2025/02-mame/authors.markdown
@@ -0,0 +1,3 @@
+* Yusuke Endoh
+ * mame@ruby-lang.org
+ * cctld: jp
diff --git a/sample/trick2025/02-mame/entry.rb b/sample/trick2025/02-mame/entry.rb
new file mode 100644
index 0000000000..d5de370dc9
--- /dev/null
+++ b/sample/trick2025/02-mame/entry.rb
@@ -0,0 +1,34 @@
+From:pd <pd-@example.com> (`)
+Date:Wed,01 Jan 2025 00:00:00 +0000
+Subject:[PATCH] +an(/.{40}/));exit].gsub(/X.*X|\n(\h+\s)?\+?/,E=""))#TRICK2025]}
+
+--- /dev/null
++++ pd.rb
+@@ -0,0 +1,27 @@
++%;`);;BEGIN{eval$s=%q[eval(%q[F=File;puts((dup)?(q="%;`);;BEGIN
++{eval$s=%q[#$s]}";U,*,V=R=(0..33.0).map{|t|q.gsub(/./){i=$`.siz
++e;c=(i/64*2i-26i+i%64-31)*1i**(t/16.5);x,y=c.rect;r=c.abs;r<13?
++4<=r&&r<6&&x>-4||-5<x&&x<=-3&&-6<y&&y<11??.:?X:$&}};B,A="---|%s
++\n+++|%s\n@@|-%s,%s|+%s,%s|@@\nFrom:pd|<pd-@example.com>|(`)\nD
++ate:%a,%d|%b|%Y|%T|%z\nSubject:[PATCH]|".tr(?|,z="\s")[/@.*\n/]
++,$`;(i=R.index(q))?(S,T=i<33?R[i,(f=->i{(Time.gm(2025)+86400*i)
++.strftime$'};o=f[i+1]+(fXXXXXXXXXXXXXXX[0]+q[/.*\z/]+?\n*2+A%["
++/dev/null",v="pd.rb"]+XXXXXXXXXXXXXXXXXXXB%[0,0,1,27]+U.gsub(/^
++/,?+)).lines[-i-2],EXXXXXXXXXXXXXXXXXXXXXXX,a=A%[v,v];V<<"\n(`\
++n#{a+B%[0,0,1,1]}+dXXXXXXXXXXXXXXXXXXXXXXXXXup=(`)";2)]:($*.siz
++e!=2&&abort(["usagXXXXXXXXX.........XXXXXXXXXe:",$0,F,F]*z);$*.
++map{o=A%$*;F.read(XXXXXXXXX..XXXXXX..XXXXXXXX_1)});a=[i=0]*v=(s
++=[s]+S.lines).sizeXXXXXXXXX..XXXXXX..XXXXXXXX;c=b=s.map{c=_1&&[
++c,?-+_1,i+=1]||0};XXXXXXXXX..XXXXXX..XXXXXXXXT.lines{|t|s.map{|
++s|a<<((s)?[x=a[-1]XXXXXXXXX.........XXXXXXXXX,y=a[-v]].max+((f=
++s==t)?1:0):0);c,d=(XXXXXXXX..XXXXXXXXXXXXXXXf)?[v+1,z+t]:s&&(x>
++y)?[1,?-+s]:[v,?++t]XXXXXXX..XXXXXXXXXXXXXX;b<<[b[-c],d,i+=1]}}
++;c=b[-1].flatten;b=c[(XXXXX..XXXXXXXXXXXX1..)%2];(b.map{_1[0]}*
++E).scan(/\s{,3}([-+]\s{,XXXXXXXXXXXXXXX6})*[-+]\s{,3}/){n=c[2*i
++=$`.size];o=o,B%[n%v+1-1/v,(m=c[2.*i+j=$&.size]-n)%v,T>""?n/v+1
++:0,m/v],b[i,j]}):(o=[];a,b=[A,B].map{_1.sub(?+){'\+'}%(['(\S+)'
++]*4)};$<.read=~//;F.write$2,(s=F.readlines$1;o<<[:patching,F,$2
++]*z;(*,n,i,m=[*$~].map{_1.to_i};n+=m;($'=~/\A((-)|\+)?(.*\n)/;$
++2?s[i-=1,1]=[]:$1?s[i-1,0]=$3:n-=1;i+=1;n-=1)while+n>0)while/\A
++#{b}/=~$';s*E)while$'=~/^#{a}/);o):([*[?l]*799,1].shuffle*E).sc
++an(/.{40}/));exit].gsub(/X.*X|\n(\h+\s)?\+?/,E=""))#TRICK2025]}
diff --git a/sample/trick2025/02-mame/remarks.markdown b/sample/trick2025/02-mame/remarks.markdown
new file mode 100644
index 0000000000..8be86ebc2d
--- /dev/null
+++ b/sample/trick2025/02-mame/remarks.markdown
@@ -0,0 +1,141 @@
+# A Lesser "Patch" Program
+
+This program is a minimalistic version of the traditional "patch" command, which looks like a patch.
+
+## Usage as a "Patch" Command
+
+The program reads a unified diff file from standard input and applies the changes to the specified files.
+
+To apply `test.patch` to `sample.rb`, use the following commands:
+
+```
+$ cp sample.orig.rb sample.rb
+$ ruby entry.rb < test.patch
+```
+
+After running these commands, verify that `sample.rb` has been modified.
+
+## Usage as a Patch File
+
+Interestingly, this program is not just a patch-like tools -- it *is* a patch.
+This duality allows it to be applied like a regular patch file.
+
+The following will create a file named pd.rb.
+
+```
+$ patch < entry.rb
+```
+
+Alternatively, you can achieve the same result using `entry.rb`:
+
+```
+$ ruby entry.rb < entry.rb
+```
+
+The generated `pd.rb` produces a new patch.
+
+```
+$ ruby pd.rb
+```
+
+The produced patch is self-referential, targeting `pd.rb` itself.
+To apply it:
+
+```
+$ ruby pd.rb | ruby entry.rb
+```
+
+You'll notice the `p` logo rotates slightly counterclockwise.
+
+The modified `pd.rb` outputs the patch for itself again, apply the patch repeatedly--a total of 33 times!
+
+## From `p` to `d`
+
+The center `p` logo symbolizes a "patch."
+When rotated 180 degrees, it resembles a `d`, signifying a transformation in functionality.
+`pd.rb` now operates as a simplified "diff" command:
+
+```
+$ ruby pd.rb
+usage: pd.rb File File
+
+$ ruby pd.rb sample.orig.rb sample.rb
+--- sample.orig.rb
++++ sample.rb
+...
+```
+
+## Integration with Git
+
+The patches are compatible with Git's `git am` command, which imports patches in mbox format.
+
+Start fresh by removing `pd.rb` and initializing a Git repository:
+
+```
+$ rm -f pd.rb
+$ git init
+Initialized empty Git repository in /home/...
+```
+
+And import `entry.rb` as a patch to the repository:
+
+```
+$ git am --committer-date-is-author-date entry.rb
+Applying: +(/.{40}/));exit].gsub(/X.*X|\n(\h+\s)?\+?/,E=""))#_TRICK2025_]}
+applying to an empty history
+```
+
+Verify the commit history:
+
+```
+$ git log
+commit 1e32693f11c1df77bd797c7b3e9f108a3e139824 (HEAD -> main)
+Author: pd (`) <pd-@example.com>
+Date: Wed Jan 1 00:00:00 2025 +0000
+
+ +an(/.{40}/));exit].gsub(/X.*X|\n(\h+\s)?\+?/,E=""))#TRICK2025]}
+```
+
+Notice that the Author and Date are properly set.
+
+To apply subsequent patches:
+
+```
+$ for i in `seq 0 32`; do ruby pd.rb | git am --committer-date-is-author-date; done
+```
+
+*(A fun details: you will see the `b` logo!)*
+
+Now, view a commit history by the following command:
+
+```
+$ git log --oneline
+```
+
+You will rediscover the original `entry.rb` unexpectedly.
+
+If you set `--committer-date-is-author-date` appropriately, you should be able to run the output of `git log --oneline` as is.
+
+Try this unusual command:
+
+```
+$ git log --oneline | ruby - test.patch
+```
+
+## A Little Something Extra
+
+Interestingly, `pd.rb` -- functioning as a diff command -- is a patch to itself.
+Reveal hidden details with:
+
+```
+$ ruby entry.rb pd.rb
+$ ruby pd.rb
+```
+
+Can you spot the difference?
+
+## Limitations
+
+* I tested it with ruby 3.3.6, git 2.45.2, and GNU patch 2.7.6.
+* No error check at all. The lesser patch do not care if there is a discrepancy between what is written in the patch and the input file, and will write over the existing file without prompt.
+* It is assumed that the text files have a new line at the end.
diff --git a/sample/trick2025/02-mame/sample.orig.rb b/sample/trick2025/02-mame/sample.orig.rb
new file mode 100644
index 0000000000..3d880b387d
--- /dev/null
+++ b/sample/trick2025/02-mame/sample.orig.rb
@@ -0,0 +1,8 @@
+def add(a, b)
+ a + b
+end
+
+if __FILE__ == $0
+ result = add(3, 5)
+ puts "Three plus five is #{ result }"
+end
diff --git a/sample/trick2025/02-mame/test.patch b/sample/trick2025/02-mame/test.patch
new file mode 100644
index 0000000000..0a63ae8a4c
--- /dev/null
+++ b/sample/trick2025/02-mame/test.patch
@@ -0,0 +1,16 @@
+--- sample.rb
++++ sample.rb
+@@ -2,7 +2,13 @@
+ a + b
+ end
+
++def sub(a, b)
++ a - b
++end
++
+ if __FILE__ == $0
+ result = add(3, 5)
+ puts "Three plus five is #{ result }"
++ result = sub(5, 3)
++ puts "five minus three is #{ result }"
+ end
diff --git a/sample/trick2025/03-tompng/authors.markdown b/sample/trick2025/03-tompng/authors.markdown
new file mode 100644
index 0000000000..26ebe24da6
--- /dev/null
+++ b/sample/trick2025/03-tompng/authors.markdown
@@ -0,0 +1,3 @@
+* Tomoya Ishida (tompng)
+ * tomoyapenguin@gmail.com
+ * cctld: jp
diff --git a/sample/trick2025/03-tompng/entry.rb b/sample/trick2025/03-tompng/entry.rb
new file mode 100644
index 0000000000..0de2244979
--- /dev/null
+++ b/sample/trick2025/03-tompng/entry.rb
@@ -0,0 +1,74 @@
+eval->{%w[u=*? a..?i;l=*?j..? r;o=*?s..?z,?_
+;m='#-*&|^`!@$ '.chars;s=[[3] ,[0,1,3,4,6],[
+1,5],[1,4],[0, 4,6],[2,4],[2] ,[1,3,4,6],[],
+ [4], ];a= (0.. 7).m ap{[
+ ?;*_ 1+'a 4',: a1,? x*(_
+ 1+2) ]*"T /#{? x.*6 7-_1
+ }/x; "};v =([c =[?x *150
+ ]*4, a.reverse,[[6, 3,0].map{"a#{_
+ 1}T/ #{?x*15}/x"}*( ?;*42)+';xx']*
+ 30,a .map{_1.tr'14' ,'25'},c,]*n=$
+ /).g sub( /(^| ;)(;
+ *);/ ){$1 +?x* $2.s
+ ize+ ?;}; p,e= [0,1
+ ].ma p{|t |g=( ["(m
+ fT/' /;#{a=(0..9).m ap{"f#{_1}T/l#
+ {_1} =1./"}*?;};C"' ;#{a.tr'l',?u}
+ ;?C" ",(0..9).map{| i|a="l#{i}T/'/
+
+
+;C"' ;";b ="#{o[i-1]+?=i fTi>0}%+";(1..
+9).m ap{a <<l[_1-1]+"T/% #{c=m[_1]}/;";
+b<<c +";# {(d=_1+i)>10?' ca='+o[d-11]:d
+>9?' ca': o[d- 1]}=
+%"+c };a+ b+[m [1..
+],?+ ,?"] *';? '},"
+caT/ '/;C "';" +(1.
+.8).map{u[8-_1 ]+"T/#{u[9-_1] }=1./;"}*''+u[
+0]+h='=1;?"',( 1..9).map{|i|" u#{i}T/'/;C"';
+"+(0..8-i).map {u[8-i-_1]+"T/ #{u[8-_1]}=1./
+ ;"}* ''+u [i-1 ]+h}
+ ]*?; ).sp lit( /([^
+ ;]+; )/); ((0. .43)
+ .map {|y| c='' ;q=-
+ >{a= (y-22).abs;b=( c.size+_1-78).
+ abs; [a<7&&b<59||b< 15,(b-30).abs<
+ 14][ t]};110.times{ c+=q[8]?g.shif
+
+
+ t||? ;:q[-t]??;:'T' };c.gsub(';T',
+ 'TT' ).rstrip}*n).g sub(/(;|T)(;;+
+ )(;| $)/){$1+'/'+?x *($2.size-2)+'
+ /'+$ 3}}; F=Fi
+ le;1 0.ti mes{
+ |i|a ="(n fT/m
+ f=l# {i}= '/;n
+ f=f# {i}=?';def/("+ s[i].map!{"a#{
+ _1}" }*','+')=(';F. write"#{i}",a+
+ ?x*( 150-a.size)+n+ v[..-5]+'))&&'
+ +n}; a,*b ="/)
+ &&de f((C nCn<
+ <A"; c=") )./(
+ ";d= 'T}' ,?A,
+ '__= <<B';u.map{|v| b<<v+"TT%(T<<#
+ {v}T )TT";d=d,v,"AC n#{v}=<<B"};o.
+ zip( l,m){a+=?;+_1+ "T/%#{_3}/";c+
+
+
+=(_3[?#]||?#+_
+3)+"))./("+_2+
+?,};F.write'+'
+,n*2 6+[p [..-
+10]+ (a+c ).tr ('!@',%("')).g
+sub( /%([ '"`] )/,){$1},'#{TT
+T'+b *';T T'+d *n,?B,')=']*n+
+n;a, b=[u ,o].map{|v|(0.
+.8). map{ t=s[9-_1];t[0]
+&&t+ =[1] ;v[8-_1]+"T/#{
+t*?= }#/" }*?; +';a3='+?x*25}
+;F.w rite '=', [n*26]*2*e+a+n
++v+n +(b+ n+v) .tr(?a,?b)[..-
+9]+' )if~ exit
+'+n].join.tr('
+TRICK',_1)}[+"
+\x2025"<<-?\\]
diff --git a/sample/trick2025/03-tompng/remarks.markdown b/sample/trick2025/03-tompng/remarks.markdown
new file mode 100644
index 0000000000..7f3f4ac6cf
--- /dev/null
+++ b/sample/trick2025/03-tompng/remarks.markdown
@@ -0,0 +1,146 @@
+### Remarks
+
+Run it with no argument. It will generate 12 files: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + and =.
+
+```sh
+ruby entry.rb
+```
+
+Concat and syntax highlight them.
+
+```sh
+cat 2 0 + 2 5 = | ruby -run -e colorize
+cat 4 + 1 5 + 4 + 1 8 = | ruby -run -e colorize
+```
+
+I confirmed the following implementations/platforms:
+
+* ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +YJIT +MN +PRISM [arm64-darwin22]
+* ruby 3.3.0 (2023-12-25 revision 5124f9ac75) +YJIT +MN [arm64-darwin22]
+
+### Description
+
+Did you know that Ruby syntax can perform additive operations on two-digit numbers without Ruby runtime? This entry demonstrates a syntax level computation of Ruby grammar.
+
+`ruby entry.rb` will generate 12 files: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + and =.
+These files constitute a calculator system that runs on Ruby parser.
+
+To calculate `6 + 7`, concat `6`, `+`, `7` and `=`.
+
+```sh
+cat 6 + 7 =
+```
+
+The concatenated output is a Ruby script that does nothing. It is also an ASCII art of `█ + █ = ██` rotated 90 degrees.
+Now, let's try syntax highlighting that code.
+
+```sh
+cat 6 + 7 = | ruby -run -e colorize
+```
+
+Wow! You can see the calculation result `6 + 7 = 13` as a colorized ASCII art!
+
+This system can also add more than two numbers. All numbers should be one or two digits, and the answer should be less than 100.
+
+```sh
+cat 3 1 + 4 + 1 5 + 9 = | ruby -run -e colorize
+cat 1 + 2 + 4 + 8 + 1 6 + 3 2 = | ruby -run -e colorize
+cat 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 1 0 = | ruby -run -e colorize
+```
+
+If the syntax highlighting is hard to see, use this command to change the terminal color.
+
+```sh
+printf "\e]11;#000000\a\e]10;#333333\a\e]4;1;#ffaaaa\a"
+```
+
+### Internals
+
+To perform calculation, you need a storage and a control flow statement.
+Local variable existence can be used as a storage.
+Ruby syntax provides conditional local variable definition and local variable reset with state carry over which can be used as a control flow statement.
+
+#### Conditional Local Variable Definition
+
+Ruby syntax can define new local variables conditionally.
+
+```ruby
+# Defines x and y if a is defined
+a /x = y = 1./
+# Defines x and y if a is not defined
+a /1#/; x = y = 1
+# Defines x or y depend on the existence of local variable a
+a /(x=1);'/;(y=1);?'
+```
+
+#### Local Variables Reset
+
+Local variables can be cleared by creating a new `def` scope.
+
+```ruby
+x = y = z = 1
+def f
+# x, y, z are cleared
+```
+
+#### State Carry Over
+
+Some state should be carried over to the next `def` scope. There are two tricks to do it.
+
+```ruby
+a /%+/i; b /%-/i; def f(x)# +; def f(y) # -; def f(z)
+```
+
+```ruby
+a %(<<A); b %(<<B); def f
+x=<<C
+A
+y=<<C
+B
+z=<<C
+C
+```
+
+In both examples above, local variable defined in the new scope will be:
+
+```ruby
+x # if both a and b are not defined
+y # if a is defined
+z # if b is defined
+```
+
+Combining these two tricks, Ruby syntax can carry over two states to the next `def` scope. In this system, two states represents upper digit and lower digit.
+
+### File Structure
+
+```ruby
+# File 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
+(code) &&
+```
+
+```ruby
+# File +
+(code) && def f(arg)=
+```
+
+```ruby
+# File =
+(code) if exit
+```
+
+```ruby
+# cat 1 2 + 3 + 4 5 =
+(one) &&
+(two) &&
+(plus) && def f(arg)=
+(three) &&
+(plus) && def f(arg)=
+(four) &&
+(five) &&
+(equal) if exit
+```
+
+### Limitation
+
+Number to be added must be one or two digits.
+Answer of the addition must be less than 100.
diff --git a/sample/trick2025/04-tompng/authors.markdown b/sample/trick2025/04-tompng/authors.markdown
new file mode 100644
index 0000000000..26ebe24da6
--- /dev/null
+++ b/sample/trick2025/04-tompng/authors.markdown
@@ -0,0 +1,3 @@
+* Tomoya Ishida (tompng)
+ * tomoyapenguin@gmail.com
+ * cctld: jp
diff --git a/sample/trick2025/04-tompng/entry.rb b/sample/trick2025/04-tompng/entry.rb
new file mode 100644
index 0000000000..881c1af871
--- /dev/null
+++ b/sample/trick2025/04-tompng/entry.rb
@@ -0,0 +1,36 @@
+ $c=%q@E="
+ \e[4%d;37m%s\e[m"
+ ;n=32.chr;pu ts"\e
+ [H\e[J#{$c=n*54+' $c=%
+ q'+[64.chr]*2*$c+';e val$
+ c.'+n*10+"\n"+n*57+"spl it*'
+ '"+n*15}";n=l=0;R=->y=0 {n+=1
+ ;l=$c.lines. map{|m|m=(0..79).chunk{380-n+
+ 36*Math.sin(0.04.*it-n )<9*y}.map{a=_2.map{m[it]}*''
+ ;_1&&E%[6,a]||a}*'';m!=l[~-y +=1]&&$><<"\e[#{y}H#{m}\e[37H
+ ";m}};N=(Integer$* [-1]resc ue+30)*H=44100;alias:r:rand
+ ;F=->e,w=1{a=b=c=0;d=( 1-e)**0 .5*20;->v=r-0.5{a=a*w*e+v
+ ;b=b*w*e*e+v;d.*a-2*b+c=c*w *e**3+ v}};A=->u,n,t{(0..n).
+ map{|i|u=u.shuffle.map{|w|R[]; a=u.s ample;b,c,d=[[0.5
+ ,(0.2+r)*H/3*1.1**i,[[1+r/10,1+r/ 10]][ i]||[1.2+
+ r/10,1.3+r/5]],[0.3,r*H/2,[1,1+r/5 ]]][t
+];e,f=d.shuffle;g=b+r;h=b+r;(0..[w. size/e, a.size/f
++c].max).map{g*(w[it*e]||0)+h*(a[[it-c,0].ma x*f]||0)}}}};j=A[A
+[(0..9).map{a=F[0.998,1i**0.02];(0..28097).m ap{a[].real.*0.1**(8.0*i
+t/H)-8e-6}},14,0].transpose.map{|d|a=[0]*3e3 ;15.times{|i|R [];b=r
+ (3e3);d[i].each_with_index{a[c=_2+b]=(a[c] ||0)+_1*0.63**i}} ;a},9,
+ 1][4..].flatten(1).shuffle;y=(0..3).map{F[ 1-1e-5]};m=[-1,1].map {[F[1
+ -1e-4],F[1-5e-5],it]};u=v=w=0;k=[],[],[] ;z=F[0.7,1i**0.5];File.o pen($
+ *.grep(/[^\d]/)[0]||'output.wav','wb') {|f|f<<'RIFF'+[N*4+36,'WA VEfmt
+ ',32,16,1,2,H,H*4,4,16,'data',N*4].p ack('Va7cVvvVVvva4V');N.tim es{|
+ i|$><<E%[4,?#]if(i+1)*80/N!=i*80 /N;t=[i/1e5,(N-i)/2e5,1].min;a,b,c=k
+ .map{it.shift||(j[20*r,0]=[g =j.pop];a=1+r/3;it[0..]=(0..g.size).m
+ ap{g[it*a]||0};0)};u=u *0.96+r-0.5;v=v*0.99+d=r-0.5;w=w*0.8+d
+ ;x=(z[].*1+0 .59i).imag;e=y.map(&:[]);f.<<m.map{|o,
+ p,q|r=a+(b+c)/2+(b-c)*q/5;s=o[r.abs]
+ ;r=t*t*(3-2*t)*(r+s*w/1e4+p[s]*x/1
+ e7+[[u,0],[v,1]].sum{_1*1.5**(e[
+ _2]+q*e[_2+2]/9)}/32)/9;r/(1
+ +r*r)**0.5*32768}.pack'v
+ *'}};puts@;eval$c.
+ split*''
diff --git a/sample/trick2025/04-tompng/remarks.markdown b/sample/trick2025/04-tompng/remarks.markdown
new file mode 100644
index 0000000000..b2d848c07c
--- /dev/null
+++ b/sample/trick2025/04-tompng/remarks.markdown
@@ -0,0 +1,43 @@
+# Seashore - Nature Sound
+
+Listen to the relaxing sound of ocean waves generated by Ruby.
+
+## Usage
+
+```sh
+ruby entry.rb
+ruby entry.rb seashore.wav 60
+```
+
+The default filename is `output.wav` and the default duration is 30 seconds.
+
+Tested with ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +YJIT +MN +PRISM [arm64-darwin22]
+
+## Noise
+
+Noise sound is created by applying low-pass/band-pass filter to a white noise signal.
+Volume of the noise should change over time. This is also calculated by using low-pass filter.
+
+## Wave
+
+Sound of a single ocean wave is composed of hundreds of water splash sounds.
+Each water splash sound is composed of thousands of water drops and bubbles.
+This program creates this complicated sound by repeating sound mixing.
+
+```ruby
+sound2 = mix(sound1.change_pitch(rand), sound1.change_pitch(rand).delay(rand))
+sound4 = mix(sound2.change_pitch(rand), sound2.change_pitch(rand).delay(rand))
+...
+sound32768 = mix(sound16384.change_pitch(rand), sound16384.change_pitch(rand).delay(rand))
+
+splash1 = mix(sound1.delay(rand), sound2.delay(rand), sound4.delay(rand), ..., sound16384.delay(rand))
+splash2 = mix(splash1.change_pitch(rand), splash1.change_pitch(rand).delay(rand))
+splash4 = mix(splash2.change_pitch(rand), splash2.change_pitch(rand).delay(rand))
+...
+splash1024 = mix(splash512.change_pitch(rand), splash512.change_pitch(rand).delay(rand))
+
+wave_sound = [splash32, splash64, ..., splash1024].sample
+```
+
+This kind of repetition is often used in fractal rendering. In other words, this operation is rendering a fractal shape to the spectrogram canvas.
+It's an efficient way to create complex structure with low computational cost.
diff --git a/sample/trick2025/05-tompng/authors.markdown b/sample/trick2025/05-tompng/authors.markdown
new file mode 100644
index 0000000000..26ebe24da6
--- /dev/null
+++ b/sample/trick2025/05-tompng/authors.markdown
@@ -0,0 +1,3 @@
+* Tomoya Ishida (tompng)
+ * tomoyapenguin@gmail.com
+ * cctld: jp
diff --git a/sample/trick2025/05-tompng/entry.rb b/sample/trick2025/05-tompng/entry.rb
new file mode 100644
index 0000000000..4d30c5b5a9
--- /dev/null
+++ b/sample/trick2025/05-tompng/entry.rb
@@ -0,0 +1,118 @@
+module ReadableFizzBuzz
+ module Chain
+ end
+end
+
+include ReadableFizzBuzz
+
+Chain::Itself = Chain
+
+module Chain::Itself
+ module Void
+ A = B = C = D = E = F = G = H = I = J = K = L = M = Void
+ N = O = P = Q = R = S = T = U = V = W = X = Y = Z = Void
+
+ module Set
+ end
+
+ module Put
+ end
+
+ module WriteBack
+ end
+
+ module Not
+ include Void
+ end
+ end
+
+ module Off
+ include Void
+ end
+
+ module Nil
+ A = B = C = D = E = F = G = H = I = J = K = L = M = Off
+ N = O = P = Q = R = S = T = U = V = W = X = Y = Z = Off
+ end
+
+ module Next
+ include Nil
+ end
+
+ module Current
+ include Nil
+
+ Not = Off
+ Set = Put = Next
+ WriteBack = Current
+ end
+
+ True = If = Current
+ On = Next
+
+ module On
+ INT = 1
+ FIZZ = 'Fizz'
+ BUZZ = 'Buzz'
+ PREFIX = '0b'
+ FORMAT = "%d%s%s\n"
+ NEXT = __FILE__
+ end
+
+ module Off
+ INT = 0
+ FIZZ = BUZZ = nil
+ PREFIX = '0b1'
+ FORMAT = "%2$s%3$s\n"
+ NEXT = '/dev/null'
+ Not = True
+ end
+
+ module Initial
+ C = D = True
+ end
+
+ module ReadableFizzBuzz::Chain::Current
+ include Initial
+ end
+
+ If::C::Set::E = If::E::Set::F = If::F::Set::C = On
+ If::D::Set::G = If::G::Set::H = If::H::Set::I = If::I::Set::J = If::J::Set::D = On
+ If::F::Not::J::Not::Set::B = On
+ If::K::Not::Set::K = On
+ If::K::WriteBack::L = True
+ If::L::Not::M::Set::M = On
+ If::L::M::Not::Put::M = On
+ If::L::M::WriteBack::N = True
+ If::N::Not::O::Set::O = On
+ If::N::O::Not::Put::O = On
+ If::N::O::WriteBack::P = True
+ If::P::Not::Q::Set::Q = On
+ If::P::Q::Not::Put::Q = On
+ If::P::Q::WriteBack::R = True
+ If::R::Not::S::Set::S = On
+ If::R::S::Not::Put::S = On
+ If::R::S::WriteBack::T = True
+ If::T::Not::U::Set::U = On
+ If::T::U::Not::Put::U = On
+ If::T::U::WriteBack::V = True
+ If::V::Not::W::Set::W = On
+ If::V::W::Not::Put::W = On
+ If::V::W::WriteBack::X = True
+ If::X::Not::Y::Set::Y = On
+ If::X::Y::Not::Put::Y = On
+ If::X::Y::WriteBack::Z = True
+ If::Z::Not::Set::A = On
+end
+
+module Chain::Chain
+ Current = Chain::Next
+end
+
+include Chain
+
+module Chain::Current
+ NUMBER = A::PREFIX, Y::INT, W::INT, U::INT, S::INT, Q::INT, O::INT, M::INT, K::INT
+ printf B::FORMAT, NUMBER.join, C::FIZZ, D::BUZZ
+ load A::NEXT
+end
diff --git a/sample/trick2025/05-tompng/remarks.markdown b/sample/trick2025/05-tompng/remarks.markdown
new file mode 100644
index 0000000000..adb4bf4df8
--- /dev/null
+++ b/sample/trick2025/05-tompng/remarks.markdown
@@ -0,0 +1,106 @@
+### Remarks
+
+Just run it with no argument:
+
+```sh
+ruby entry.rb
+```
+
+I confirmed the following implementations/platforms:
+
+- ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +YJIT +MN +PRISM [arm64-darwin22]
+- ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [aarch64-linux-musl]
+
+### Description
+
+Readability is important even for a simple fizz buzz program.
+
+These are the major ingredients of a spaghetti that makes program tasty and valuable but unreadable.
+
+- Many class definitions
+- Many method definitions
+- Many method calls
+- Many variables
+- Conditional branches
+
+These are what is acceptable for a readable program.
+
+- Many modules: Using only a single module in a program is not good.
+- Many constants: Better than magic numbers.
+- Module#include: Mixins are what module is for.
+- Many file loads: Usually better than loading a large file only once.
+- Minimal method calls: Needed for printing output.
+
+This program is doing something slightly difficult in the last few lines: print output and load ruby program.
+In contrast, the rest part of this program is extremely simple and easy. Module definition, constant definition and module inclusion. That's all.
+
+### Internals
+
+Called methods
+
+- `Module#include`
+- `Array#join`
+- `Kernel#printf`
+- `Kernel#load`
+
+Deeply nested module chain to avoid constant reassignment
+
+```ruby
+10.times do
+ module Root
+ module Chain
+ module X; end
+ module Y; end
+ module Z; end
+ end
+ end
+ include Root
+
+ module Chain::Chain
+ # Not a constant reassignment because Chain::Chain is always a new module
+ X = Chain::Y
+ Y = Chain::Z
+ Z = Chain::X
+ end
+ include Chain
+ p x: X, chain: Chain
+end
+```
+
+Constant allocation
+
+| Constant | Purpose |
+| ---------------------- | ----------------------- |
+| A | Loop condition |
+| B | Format (!Fizz && !Buzz) |
+| C, E, F | Fizz rotation |
+| D, G, H, I, J | Buzz rotation |
+| K, M, O, Q, S, U, W, Y | Iteration bits |
+| L, N, P, R, T, V, X, Z | Temporary carry bits |
+
+Instruction sequence with constant lookup magic
+
+```ruby
+# B = 1 if A
+If::A::Set::B = On
+
+# B = 1 if !A
+If::A::Not::Set::B = On
+
+# C = 1 if !A && B
+If::A::Not::B::Set::C = On
+
+# C = 1 if !A && !B
+If::A::Not::B::Not::Set::C = On
+```
+
+Loop with `load __FILE__`
+
+```ruby
+# A::NEXT is __FILE__ or '/dev/null'
+load A::NEXT
+```
+
+### Limitation
+
+Needs `/dev/null`
diff --git a/sample/trick2025/README.md b/sample/trick2025/README.md
new file mode 100644
index 0000000000..1d71f54620
--- /dev/null
+++ b/sample/trick2025/README.md
@@ -0,0 +1,16 @@
+This directory contains the top-five entries of
+the 5th Transcendental Ruby Imbroglio Contest for rubyKaigi (TRICK 2025).
+
+THESE ARE BAD EXAMPLES! You must NOT use them as a sample code.
+
+* 1st: "Most Revolutionary" - Don Yang
+* 2nd: "Most Useful" - Yusuke Endoh
+* 3rd: "Most Arithmetic" - Tomoya Ishida
+* 4th: "Best ASMR" - Tomoya Ishida
+* 5th: "Most Maintainable" - Tomoya Ishida
+
+These files are licensed under MIT license.
+
+For the contest outline and other winning entries, see:
+
+https://github.com/tric/trick2025
diff --git a/sample/uumerge.rb b/sample/uumerge.rb
index 2576bcb864..1b81582c24 100644
--- a/sample/uumerge.rb
+++ b/sample/uumerge.rb
@@ -15,7 +15,7 @@ while line = gets()
if out_stdout
out = STDOUT
else
- out = open($file, "w") if $file != ""
+ out = File.open($file, "w") if $file != ""
end
out.binmode
break