Skip to content
Snippets Groups Projects
Commit 096d58d6 authored by pjs's avatar pjs
Browse files

Merge branch 'varargs'

parents b72ce230 760fe857
No related branches found
No related tags found
No related merge requests found
...@@ -11,10 +11,13 @@ class MyModel ...@@ -11,10 +11,13 @@ class MyModel
end end
def increment(n:, char:) def increment(n:, char:)
@x += n if model_time < 10.0
schedule(:increment, 2.0 * rand(2), n: @x, char: char - 1, priority: 3) @x += n
printf "%f, %f, %c\n", model_time, @x, char schedule(:increment, rand(3), n: @x, char: char - 1, priority: 3)
cancel_all :increment if model_time > 10 printf "%f, %f, %c\n", model_time, @x, char
else
cancel_all :increment
end
end end
end end
......
...@@ -54,7 +54,7 @@ module SimpleKit ...@@ -54,7 +54,7 @@ module SimpleKit
# - +args+ -> zero or more named arguments to pass to the event # - +args+ -> zero or more named arguments to pass to the event
# at invocation time. These should be specified with labels, and # at invocation time. These should be specified with labels, and
# consequently they can be placed in any order. # consequently they can be placed in any order.
def schedule(event, delay, **args) def schedule(event, delay, args = {})
raise 'Model scheduled event with negative delay.' if delay < 0 raise 'Model scheduled event with negative delay.' if delay < 0
@event_list.push EventNotice.new(event, @model_time, delay, args) @event_list.push EventNotice.new(event, @model_time, delay, args)
end end
...@@ -65,9 +65,10 @@ module SimpleKit ...@@ -65,9 +65,10 @@ module SimpleKit
# all be a match with the corresponding +args+ of the scheduled event # all be a match with the corresponding +args+ of the scheduled event
# in order for the cancellation to apply, but +args+ which are not # in order for the cancellation to apply, but +args+ which are not
# specified do not affect the target event matching. # specified do not affect the target event matching.
def cancel(event, **args) def cancel(event, args = {})
@cancel_set[event] ||= Set.new @cancel_set[event] ||= Set.new
@cancel_set[event].add(args.empty? ? nil : args) # @cancel_set[event].add(args.empty? ? nil : args)
@cancel_set[event].add(args)
end end
# Cancel all currently scheduled events of type +event+. # Cancel all currently scheduled events of type +event+.
...@@ -96,7 +97,7 @@ module SimpleKit ...@@ -96,7 +97,7 @@ module SimpleKit
if current_event.args.empty? if current_event.args.empty?
@user_model.send(current_event.event) @user_model.send(current_event.event)
else else
@user_model.send(current_event.event, current_event.args) @user_model.send(current_event.event, **current_event.args)
end end
end end
end end
......
# -*- ruby -*- # -*- ruby -*-
_VERSION = "1.0.0" _VERSION = "1.1.0"
Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = "simplekit" s.name = "simplekit"
s.version = _VERSION s.version = _VERSION
s.date = "2018-07-12" s.date = "2020-04-09"
s.summary = "Discrete event simulation engine." s.summary = "Discrete event simulation engine."
s.homepage = "https://gitlab.nps.edu/pjsanche/simplekit-ruby.git" s.homepage = "https://gitlab.nps.edu/pjsanche/simplekit-ruby.git"
s.email = "pjs@alum.mit.edu" s.email = "pjs@alum.mit.edu"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment