Skip to content
This repository

accept a Symbol as the second argument to Signal.trap(…). #2321

Merged
merged 2 commits into from about 1 year ago

1 participant

Jesse Cooke
Deleted user
ghost commented

On 1.9 mode Signal.trap can take a Symbol as a second argument in place of a
String. For example, you can say:

Signal.trap :SIGUSR1, :DEFAULT
Signal.trap :SIGUSR1, :SIG_DFT
Signal.trap :SIGUSR1, :SIG_IGN
Signal.trap :SIGUSR1, :IGNORE

I found this while trying to use Foreman on Rubinius. It has code that uses
:DEFAULT in place of "DEFAULT".

Side-note:
MRI 1.9 & 1.8 behavior is to accept any string or symbol as the second argument.
Rubinius(1.8 & 1.9) mode raise when the second argument isn't something it
understands. This is valid on CRuby, but not rubinius:

Signal.trap :SIGUSR1, "ninja"
Robert Gleeson added some commits
Robert Gleeson accept a Symbol as the second argument to Signal.trap(…).
On 1.9 mode Signal.trap can take a Symbol as a second argument in place of a
String. For example, you can say:

  Signal.trap :SIGUSR1, :DEFAULT
  Signal.trap :SIGUSR1, :SIG_DFT
  Signal.trap :SIGUSR1, :SIG_IGN
  Signal.trap :SIGUSR1, :IGNORE

I found this while trying to use Foreman on Rubinius. It has code that uses
:DEFAULT in place of "DEFAULT".

Side-note:
MRI 1.9 & 1.8 behavior is to accept any string or symbol as the second argument.
Rubinius(1.8 & 1.9) mode raise when the second argument isn't something it
understands. This is valid on CRuby, but not rubinius:

  Signal.trap :SIGUSR1, "ninja"
9f55c49
Robert Gleeson add specs. 7ebf682
Jesse Cooke jc00ke merged commit 685e78d into from
Jesse Cooke jc00ke closed this
Deleted user ghost deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Apr 29, 2013
Robert Gleeson accept a Symbol as the second argument to Signal.trap(…).
On 1.9 mode Signal.trap can take a Symbol as a second argument in place of a
String. For example, you can say:

  Signal.trap :SIGUSR1, :DEFAULT
  Signal.trap :SIGUSR1, :SIG_DFT
  Signal.trap :SIGUSR1, :SIG_IGN
  Signal.trap :SIGUSR1, :IGNORE

I found this while trying to use Foreman on Rubinius. It has code that uses
:DEFAULT in place of "DEFAULT".

Side-note:
MRI 1.9 & 1.8 behavior is to accept any string or symbol as the second argument.
Rubinius(1.8 & 1.9) mode raise when the second argument isn't something it
understands. This is valid on CRuby, but not rubinius:

  Signal.trap :SIGUSR1, "ninja"
9f55c49
Robert Gleeson add specs. 7ebf682
This page is out of date. Refresh to see the latest.
1  kernel/common/signal19.rb
@@ -21,6 +21,7 @@ def self.trap(sig, prc=nil, &block)
21 21
22 22 # If no command, use the block.
23 23 prc ||= block
  24 + prc = prc.to_s if prc.kind_of?(Symbol)
24 25
25 26 case prc
26 27 when "DEFAULT", "SIG_DFL"
20 spec/ruby/core/signal/trap_spec.rb
@@ -42,6 +42,26 @@
42 42 Signal.trap :HUP, nil
43 43 Signal.trap(:HUP, @saved_trap).should be_nil
44 44 end
  45 +
  46 + it "accepts 'DEFAULT' as a symbol in place of a proc" do
  47 + Signal.trap :HUP, :DEFAULT
  48 + Signal.trap(:HUP, :DEFAULT).should == "DEFAULT"
  49 + end
  50 +
  51 + it "accepts 'SIG_DFL' as a symbol in place of a proc" do
  52 + Signal.trap :HUP, :SIG_DFL
  53 + Signal.trap(:HUP, :SIG_DFL).should == "DEFAULT"
  54 + end
  55 +
  56 + it "accepts 'SIG_IGN' as a symbol in place of a proc" do
  57 + Signal.trap :HUP, :SIG_IGN
  58 + Signal.trap(:HUP, :SIG_IGN).should == "IGNORE"
  59 + end
  60 +
  61 + it "accepts 'IGNORE' as a symbol in place of a proc" do
  62 + Signal.trap :HUP, :IGNORE
  63 + Signal.trap(:HUP, :IGNORE).should == "IGNORE"
  64 + end
45 65 end
46 66
47 67 it "accepts long names as Strings" do

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.