Using the nfc gem

require 'nfc'

# Create a new context
ctx = NFC::Context.new

# Open the first available USB device
dev = ctx.open nil

# Block until a tag is available, then print tag info
r = dev.select

=> (NFC) ISO14443A Tag
 ATQA (SENS_RES): 00  04
    UID (NFCID1): 9D  42  4E  7C
   SAK (SEL_RES): 08
r.class    #=> NFC::ISO14443A
r.uid      #=> [157, 66, 78, 124]
r.uid.join #=> "1576678124"

# It can also be used in a continuous loop

loop do
  p dev.select
end

Note: To terminate the loop I had to kill the IRB session. The other way is to use CTRL+C and then swipe the RFID tag across the reader.

Resources