rubyrack 0.1.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 +7 -0
- data/lib/RubyRack.rb +73 -0
- metadata +60 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: fc2bac3adc735eb7f9a7aceeb3866d48042bea528ecf9308ad18af1367057d57
|
|
4
|
+
data.tar.gz: 8027c277b5855d67e005fe4f2e06f663ea6a877185eebffdc89a26a00e68d324
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: c05b81c2c98a1ec68039f453d7243f96ab6f78d7c8065e28bc9c5b73b939b062961bad333b472fbf90d1f4d5abab0b355462465ff2325a82e3b5bd7111c172b4
|
|
7
|
+
data.tar.gz: e7c98a1775ffe15b4487a0e98f8e8913ba4dbd407e2448d2b0d52d2b97691c74fd0c60b19d8277b3ce234f601b8e9f410e10bf20094181a51229c572c9721871
|
data/lib/RubyRack.rb
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
module RubyRack
|
|
2
|
+
TOTAL_MEMORY = 1 * 1024 * 1024 # 1 MB in bytes for each segment (RAM and ROM)
|
|
3
|
+
|
|
4
|
+
class Memory
|
|
5
|
+
attr_accessor :size, :data
|
|
6
|
+
|
|
7
|
+
def initialize(size)
|
|
8
|
+
@size = size
|
|
9
|
+
@data = Array.new(size, 0)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def read(address)
|
|
13
|
+
if address < @size
|
|
14
|
+
@data[address]
|
|
15
|
+
else
|
|
16
|
+
raise "Address out of bounds"
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
class RAM < Memory
|
|
22
|
+
def write(address, value)
|
|
23
|
+
if address < @size
|
|
24
|
+
@data[address] = value
|
|
25
|
+
else
|
|
26
|
+
raise "Address out of bounds"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def keep_in_memory(address, value)
|
|
31
|
+
write(address, value)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def keep_in_memory_gracefully(address, value)
|
|
35
|
+
begin
|
|
36
|
+
write(address, value)
|
|
37
|
+
rescue StandardError => e
|
|
38
|
+
puts "Error: #{e.message}"
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
class ROM < Memory
|
|
44
|
+
def initialize(size, initial_data = [])
|
|
45
|
+
super(size)
|
|
46
|
+
initial_data.each_with_index do |value, index|
|
|
47
|
+
@data[index] = value
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def write(address, _value)
|
|
52
|
+
raise "Cannot write to ROM"
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Example usage:
|
|
58
|
+
ram = RubyRack::RAM.new(RubyRack::TOTAL_MEMORY) # Allocate 1 MB to RAM
|
|
59
|
+
rom = RubyRack::ROM.new(RubyRack::TOTAL_MEMORY, [1, 2, 3, 4]) # Allocate 1 MB to ROM with initial data
|
|
60
|
+
|
|
61
|
+
# Using keep_in_memory
|
|
62
|
+
ram.keep_in_memory(0, 123)
|
|
63
|
+
puts ram.read(0) # Output: 123
|
|
64
|
+
|
|
65
|
+
# Using keep_in_memory_gracefully
|
|
66
|
+
ram.keep_in_memory_gracefully(0, 456)
|
|
67
|
+
puts ram.read(0) # Output: 456
|
|
68
|
+
|
|
69
|
+
# Attempting an out-of-bounds write with keep_in_memory_gracefully
|
|
70
|
+
ram.keep_in_memory_gracefully(RubyRack::TOTAL_MEMORY, 789) # This should trigger an error message
|
|
71
|
+
|
|
72
|
+
puts rom.read(2) # Output: 3
|
|
73
|
+
# rom.write(2, 5) # Uncommenting this line would raise an error: "Cannot write to ROM"
|
metadata
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: rubyrack
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- cllibojjj
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2024-11-23 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rake
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '13.0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '13.0'
|
|
27
|
+
description: RubyRack is a ruby module that allows you to demostrate how computer
|
|
28
|
+
memory works!!!!.
|
|
29
|
+
email:
|
|
30
|
+
- aimaankhankvs@gmail.com
|
|
31
|
+
executables: []
|
|
32
|
+
extensions: []
|
|
33
|
+
extra_rdoc_files: []
|
|
34
|
+
files:
|
|
35
|
+
- lib/RubyRack.rb
|
|
36
|
+
homepage: https://your-gem-homepage.com
|
|
37
|
+
licenses:
|
|
38
|
+
- MIT
|
|
39
|
+
metadata:
|
|
40
|
+
allowed_push_host: https://rubygems.org
|
|
41
|
+
post_install_message: Thanks for installing RubyRack! Enjoy simulating RAM and ROM.
|
|
42
|
+
rdoc_options: []
|
|
43
|
+
require_paths:
|
|
44
|
+
- lib
|
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
46
|
+
requirements:
|
|
47
|
+
- - "~>"
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: '3.0'
|
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
requirements: []
|
|
56
|
+
rubygems_version: 3.5.22
|
|
57
|
+
signing_key:
|
|
58
|
+
specification_version: 4
|
|
59
|
+
summary: RubyRack, A Ruby library for showing how computer memory and storage works!!!.
|
|
60
|
+
test_files: []
|