Created
April 29, 2023 01:50
-
-
Save takaheraw/a205782696edff0b2d1314aaefbdccc3 to your computer and use it in GitHub Desktop.
RSフリップフロップ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RSFlipFlop | |
def initialize | |
@q = 0 | |
@q_not = 1 | |
end | |
def set | |
@q = 1 | |
@q_not = 0 | |
end | |
def reset | |
@q = 0 | |
@q_not = 1 | |
end | |
def no_change | |
# 現在の状態を維持 | |
end | |
def output | |
{q: @q, q_not: @q_not} | |
end | |
end | |
# 使用方法 | |
rs_flip_flop = RSFlipFlop.new | |
puts "初期状態: #{rs_flip_flop.output}" | |
rs_flip_flop.set | |
puts "セット状態: #{rs_flip_flop.output}" | |
rs_flip_flop.reset | |
puts "リセット状態: #{rs_flip_flop.output}" | |
rs_flip_flop.no_change | |
puts "変更なし状態: #{rs_flip_flop.output}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment