ancient_ruby 0.49.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cbae5996b347a4f7b17a9f9513d3647ca916e104454d5d6d328a8ccaf2337bbc
4
+ data.tar.gz: 726da68925453bf40ad3dd904cb0f7cbdfafd7154e3b240dbcb851c0abfa68d6
5
+ SHA512:
6
+ metadata.gz: 1b8995b30163996c34bfc7664ae48dc7c50d10eb5cbf8fe36057d41df980ae23a9dfa3471dc946eb99b46c0031dfe5163923343af23eaaee1dd469645443e2a1
7
+ data.tar.gz: 2a3a895ecfdc27da5639054a0e3e1445036dea7e71ae529becd991824f8b26e8c7a27197cbaf25a2839658e8325fae33bf8185353efd950f618a419e7d8938cd
data/LICENSE.txt ADDED
@@ -0,0 +1,26 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Chris Hasinski
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ ---
24
+
25
+ The original Ruby 0.49 source code is:
26
+ Copyright (C) 1994 Yukihiro Matsumoto
data/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # AncientRuby
2
+
3
+ Run Ruby 0.49 (from 1994!) code from modern Ruby applications.
4
+
5
+ This gem bundles Ruby 0.49, the oldest extant version of Ruby, as a universal [Cosmopolitan](https://github.com/jart/cosmopolitan) binary that runs on Linux, macOS, Windows, and FreeBSD.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ancient_ruby'
13
+ ```
14
+
15
+ Or install it directly:
16
+
17
+ ```bash
18
+ gem install ancient_ruby
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ ### From Ruby
24
+
25
+ ```ruby
26
+ require 'ancient_ruby'
27
+
28
+ # Evaluate a string of Ruby 0.49 code
29
+ output = AncientRuby.eval('"Hello from 1994!".print')
30
+ puts output # => Hello from 1994!
31
+
32
+ # Evaluate a file
33
+ output = AncientRuby.eval_file("path/to/script.rb")
34
+
35
+ # Pass arguments to a script
36
+ output = AncientRuby.eval_file("fizzbuzz.rb", "20")
37
+
38
+ # Get Ruby 0.49 version
39
+ puts AncientRuby.ruby049_version
40
+ # => ruby - version 0.49 (18 Jul 94)
41
+
42
+ # Get path to the binary
43
+ puts AncientRuby.binary_path
44
+ ```
45
+
46
+ ### From Command Line
47
+
48
+ The gem installs a `ruby-0.49` executable:
49
+
50
+ ```bash
51
+ # Run a script
52
+ ruby-0.49 script.rb
53
+
54
+ # Check version
55
+ ruby-0.49 -v
56
+
57
+ # Interactive (reads from stdin)
58
+ echo '"Hello".print' | ruby-0.49
59
+ ```
60
+
61
+ ## Ruby 0.49 Syntax
62
+
63
+ Ruby 0.49 has some interesting differences from modern Ruby:
64
+
65
+ ```ruby
66
+ # Constants use % instead of uppercase
67
+ %MAX = 100
68
+
69
+ # .print on any object
70
+ "Hello".print
71
+ 42.print
72
+
73
+ # for loops (no .each yet!)
74
+ for i in 1..10
75
+ i.print
76
+ end
77
+
78
+ # end tags
79
+ if condition then
80
+ # ...
81
+ end if
82
+
83
+ # $ARGV instead of ARGV
84
+ $ARGV[0].print
85
+ ```
86
+
87
+ ## Supported Platforms
88
+
89
+ The bundled `ruby049` binary is an Actually Portable Executable (APE) that runs on:
90
+
91
+ - Linux x86_64 / ARM64
92
+ - macOS x86_64 / ARM64
93
+ - Windows x86_64
94
+ - FreeBSD x86_64
95
+
96
+ ## License
97
+
98
+ MIT License. See [LICENSE.txt](LICENSE.txt).
99
+
100
+ The original Ruby 0.49 source code is Copyright (C) 1994 Yukihiro Matsumoto.
data/exe/ruby-0.49 ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Wrapper script for the Ruby 0.49 Cosmopolitan binary
5
+ binary = File.expand_path("ruby-0.49.com", __dir__)
6
+ exec(binary, *ARGV)
data/exe/ruby-0.49.com ADDED
Binary file
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "open3"
4
+ require "tempfile"
5
+
6
+ module AncientRuby
7
+ module Runner
8
+ class << self
9
+ # Path to the bundled Ruby 0.49 binary
10
+ def binary_path
11
+ @binary_path ||= File.expand_path("../../exe/ruby-0.49.com", __dir__)
12
+ end
13
+
14
+ # Evaluate a string of Ruby 0.49 code
15
+ def eval(code)
16
+ Tempfile.create(["ancient_ruby", ".rb"]) do |file|
17
+ file.write(code)
18
+ file.flush
19
+ execute(file.path)
20
+ end
21
+ end
22
+
23
+ # Evaluate a Ruby 0.49 script file
24
+ def eval_file(path, *args)
25
+ raise Errno::ENOENT, "No such file: #{path}" unless File.exist?(path)
26
+
27
+ execute(path, *args)
28
+ end
29
+
30
+ # Get Ruby 0.49 version
31
+ def version
32
+ stdout, _stderr, status = Open3.capture3(binary_path, "-v")
33
+ raise ExecutionError, "Failed to get version" unless status.success?
34
+
35
+ stdout.strip
36
+ end
37
+
38
+ private
39
+
40
+ def execute(script_path, *args)
41
+ ensure_binary_executable!
42
+
43
+ cmd = [binary_path, script_path, *args]
44
+ stdout, stderr, status = Open3.capture3(*cmd)
45
+
46
+ unless status.success?
47
+ error_message = stderr.empty? ? stdout : stderr
48
+ raise ExecutionError, "Ruby 0.49 execution failed: #{error_message}"
49
+ end
50
+
51
+ stdout
52
+ end
53
+
54
+ def ensure_binary_executable!
55
+ return if File.executable?(binary_path)
56
+
57
+ File.chmod(0o755, binary_path)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AncientRuby
4
+ VERSION = "0.49.0"
5
+ RUBY049_VERSION = "0.49 (18 Jul 94)"
6
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "ancient_ruby/version"
4
+ require_relative "ancient_ruby/runner"
5
+
6
+ module AncientRuby
7
+ class Error < StandardError; end
8
+ class ExecutionError < Error; end
9
+
10
+ class << self
11
+ # Evaluate a string of Ruby 0.49 code
12
+ #
13
+ # @param code [String] Ruby 0.49 code to evaluate
14
+ # @return [String] Output from the Ruby 0.49 interpreter
15
+ # @raise [ExecutionError] if the code fails to execute
16
+ #
17
+ # @example
18
+ # AncientRuby.eval('"Hello from 1994!".print')
19
+ # # => "Hello from 1994!"
20
+ #
21
+ def eval(code)
22
+ Runner.eval(code)
23
+ end
24
+
25
+ # Evaluate a Ruby 0.49 script file
26
+ #
27
+ # @param path [String] Path to the Ruby 0.49 script
28
+ # @param args [Array<String>] Arguments to pass to the script
29
+ # @return [String] Output from the Ruby 0.49 interpreter
30
+ # @raise [ExecutionError] if the script fails to execute
31
+ # @raise [Errno::ENOENT] if the file doesn't exist
32
+ #
33
+ # @example
34
+ # AncientRuby.eval_file("examples/fizzbuzz.rb")
35
+ #
36
+ def eval_file(path, *args)
37
+ Runner.eval_file(path, *args)
38
+ end
39
+
40
+ # Get the path to the Ruby 0.49 binary
41
+ #
42
+ # @return [String] Absolute path to the ruby049 executable
43
+ #
44
+ def binary_path
45
+ Runner.binary_path
46
+ end
47
+
48
+ # Get the Ruby 0.49 version string
49
+ #
50
+ # @return [String] Version string from ruby-0.49 -v
51
+ #
52
+ def ruby049_version
53
+ Runner.version
54
+ end
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ancient_ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.49.0
5
+ platform: ruby
6
+ authors:
7
+ - Sam Westerman
8
+ - Chris Hasinski
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 1980-01-02 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A gem that bundles Ruby 0.49, the oldest extant version of Ruby, as a
14
+ universal Cosmopolitan binary. Evaluate ancient Ruby code from your modern Ruby
15
+ applications.
16
+ email:
17
+ - mail@sampersand.me
18
+ - krzysztof.hasinski@gmail.com
19
+ executables:
20
+ - ruby-0.49
21
+ extensions: []
22
+ extra_rdoc_files: []
23
+ files:
24
+ - LICENSE.txt
25
+ - README.md
26
+ - exe/ruby-0.49
27
+ - exe/ruby-0.49.com
28
+ - lib/ancient_ruby.rb
29
+ - lib/ancient_ruby/runner.rb
30
+ - lib/ancient_ruby/version.rb
31
+ homepage: https://github.com/sampersand/ruby-0.49
32
+ licenses:
33
+ - MIT
34
+ metadata:
35
+ source_code_uri: https://github.com/sampersand/ruby-0.49
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 2.6.0
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubygems_version: 3.6.8
51
+ specification_version: 4
52
+ summary: Run Ruby 0.49 (1994) code from modern Ruby
53
+ test_files: []