# Nfc 1.0.0 Released

**URL:** <https://www.ruby-forum.com/t/nfc-1-0-0-released/169316>\
**Category:** Ruby\
**Created:** [June 2, 2009, 7:26am UTC](https://www.ruby-forum.com/t/nfc-1-0-0-released/169316 "2009-06-02T07:26:16Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![aaronpowell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7bcc69/32.png) [@aaronpowell](https://www.ruby-forum.com/u/aaronpowell)\
**Post date:** [June 2, 2009, 7:26am UTC](https://www.ruby-forum.com/t/nfc-1-0-0-released/169316/1 "2009-06-02T07:26:16Z")

</div>

nfc version 1.0.0 has been released!

- [http://seattlerb.rubyforge.org](http://seattlerb.rubyforge.org)

NFC is a ruby wrapper for the Near Field Communication library. The  
Near  
Field Communication library works with many USB RFID readers, so this  
gem  
lets you read RFID tags.

## FEATURES/PROBLEMS:

- Only supports ISO1443A (MIFARE) tags right now.

## SYNOPSIS:

require ‘nfc’

# Read your tag and print the info

p NFC.instance.find

## REQUIREMENTS:

- A USB RFID reader. I’m using the touchatag[[http://touchatag.com](http://touchatag.com)].
- ffi
- libnfc

## INSTALL:

- First install libnfc[[http://libnfc.org/](http://libnfc.org/)]
- Make sure libnfc.dylib or libnfc.so is in your library path
- gem install nfc

Changes:

### 1.0.0 / 2009-06-01

- 1 major enhancement

- [http://seattlerb.rubyforge.org](http://seattlerb.rubyforge.org)

---

<div class="post-metadata">

**Author:** ![aaronpowell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7bcc69/32.png) [@aaronpowell](https://www.ruby-forum.com/u/aaronpowell)\
**Post date:** [June 2, 2009, 7:01pm UTC](https://www.ruby-forum.com/t/nfc-1-0-0-released/169316/2 "2009-06-02T19:01:43Z")

</div>

Aaron P. wrote:

> require ‘nfc’
> 
> # Read your tag and print the info
> 
> p NFC.instance.find

Seems like the NFC class includes Singleton, correct?

require ‘singleton’  
class NFC  
include Singleton  
# …  
end

You could simplify your public API (by not requiring users to type  
.instance) like this:

require ‘singleton’  
NFC = Class.new do  
include Singleton  
# …  
end.instance

---

<div class="post-metadata">

**Author:** ![aaronpowell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7bcc69/32.png) [@aaronpowell](https://www.ruby-forum.com/u/aaronpowell)\
**Post date:** [June 2, 2009, 7:15pm UTC](https://www.ruby-forum.com/t/nfc-1-0-0-released/169316/3 "2009-06-02T19:15:28Z")

</div>

Suraj K. wrote:

> You could simplify your public API (by not requiring users to type  
> .instance) like this:
> 
> require ‘singleton’  
> NFC = Class.new do  
> include Singleton  
> # …  
> end.instance

Module functions are good for this too.

module NFC  
def find(\*args)  
puts \*args  
end  
module\_function :find  
end

NFC.find(“123”)

class Foo  
include NFC  
def bar  
find(“456”)  
end  
end

Foo.new.bar

---

<div class="post-metadata">

**Author:** ![aaronpowell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7bcc69/32.png) [@aaronpowell](https://www.ruby-forum.com/u/aaronpowell)\
**Post date:** [June 3, 2009, 1:18am UTC](https://www.ruby-forum.com/t/nfc-1-0-0-released/169316/4 "2009-06-03T01:18:11Z")

</div>

Aaron P. wrote:

> On Wed, Jun 03, 2009 at 02:01:45AM +0900, Suraj K. wrote:
> 
> > ```
> > include Singleton
> > 
> > ```
> > 
> > end.instance
> 
> That would create a new instance of the object as soon as the gem is  
> required, and that might not be desired. Especially when dealing with a  
> piece of hardware.

In that case, use Kernel#autoload to load your library only when the NFC  
constant is actually used:

autoload :NFC, ‘nfc’

Then your users can simply write:

NFC.find

---

<div class="post-metadata">

**Author:** ![aaronpowell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7bcc69/32.png) [@aaronpowell](https://www.ruby-forum.com/u/aaronpowell)\
**Post date:** [June 3, 2009, 1:30am UTC](https://www.ruby-forum.com/t/nfc-1-0-0-released/169316/5 "2009-06-03T01:30:54Z")

</div>

On Jun 2, 2009, at 16:18, Suraj K. wrote:

> In that case, use Kernel#autoload to load your library only when the  
> NFC  
> constant is actually used:
> 
> autoload :NFC, ‘nfc’
> 
> Then your users can simply write:
> 
> NFC.find

You have to require ‘nfc’ to get the autoload, so this won’t work.  
Adding two files to do this is far lamer than Singleton.

If you’re really dead set on it, why don’t just fork it? I’m quite  
certain Aaron won’t care.

---

<div class="post-metadata">

**Author:** ![aaronpowell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7bcc69/32.png) [@aaronpowell](https://www.ruby-forum.com/u/aaronpowell)\
**Post date:** [June 3, 2009, 6:16am UTC](https://www.ruby-forum.com/t/nfc-1-0-0-released/169316/6 "2009-06-03T06:16:48Z")

</div>

Eric H. wrote:

> You have to require ‘nfc’ to get the autoload, so this won’t work.

I beg to differ; you need not require() before using autoload():

sun@yantram ~/tmp\> cat nfc.rb  
NFC = Class.new do  
require ‘singleton’  
include Singleton

```
def find(*args)
  p :find => args
end

```

end.instance

p :loaded\_nfc

sun@yantram ~/tmp\> cat run\_this.rb  
autoload :NFC, ‘nfc’  
NFC.find(‘123’)

sun@yantram ~/tmp\> multiruby run\_this.rb

VERSION = 1.8.7-p72  
CMD = ~/.multiruby/install/1.8.7-p72/bin/ruby run\_this.rb

:loaded\_nfc  
{:find=\>[“123”]}

RESULT = 0

VERSION = 1.8.6-p368  
CMD = ~/.multiruby/install/1.8.6-p368/bin/ruby run\_this.rb

:loaded\_nfc  
{:find=\>[“123”]}

RESULT = 0

VERSION = 1.9.1-p0  
CMD = ~/.multiruby/install/1.9.1-p0/bin/ruby run\_this.rb

:loaded\_nfc  
{:find=\>[“123”]}

RESULT = 0

VERSION = jruby-1.2.0  
CMD = ~/.multiruby/install/jruby-1.2.0/bin/ruby run\_this.rb

:loaded\_nfc  
{:find=\>[“123”]}

RESULT = 0

TOTAL RESULT = 0 failures out of 4

Passed: 1.8.6-p368, 1.8.7-p72, jruby-1.2.0, 1.9.1-p0  
Failed:

> Adding two files to do this is far lamer than Singleton.

Why would you need two files? Because NFC is a gem?

Since RubyGems overrides Kernel#require() and Kernel#autoload() uses  
Kernel#require(), the autoload approach should work even if loading NFC  
from a gem.

---

<div class="post-metadata">

**Author:** ![aaronpowell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7bcc69/32.png) [@aaronpowell](https://www.ruby-forum.com/u/aaronpowell)\
**Post date:** [June 2, 2009, 10:31pm UTC](https://www.ruby-forum.com/t/nfc-1-0-0-released/169316/7 "2009-06-02T22:31:47Z")

</div>

On Wed, Jun 03, 2009 at 02:01:45AM +0900, Suraj K. wrote:

> ```
> include Singleton
> 
> ```
> 
> end.instance  
> That would create a new instance of the object as soon as the gem is  
> required, and that might not be desired. Especially when dealing with a  
> piece of hardware.

---

<div class="post-metadata">

**Author:** ![aaronpowell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7bcc69/32.png) [@aaronpowell](https://www.ruby-forum.com/u/aaronpowell)\
**Post date:** [June 3, 2009, 10:54am UTC](https://www.ruby-forum.com/t/nfc-1-0-0-released/169316/8 "2009-06-03T10:54:32Z")

</div>

On Jun 2, 2009, at 21:16 , Suraj K. wrote:

> Eric H. wrote:
> 
> > You have to require ‘nfc’ to get the autoload, so this won’t work.
> 
> I beg to differ; you need not require() before using autoload():

yes… but you have to put that autoload SOMEWHERE. Otherwise, what’s  
the point? You should have been able to intuit that eric understood  
this by stating “adding two files to do this is far lamer than  
Singleton”.

I believe it is fair to say at this point that nobody involved with  
nfc cares about “improving” the API as you’re suggesting. There isn’t  
anything wrong with typing “instance”. As Eric stated, if you’ve got  
such a boner for autoload, you’re welcome to fork.

---

<div class="post-metadata">

**Author:** ![aaronpowell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7bcc69/32.png) [@aaronpowell](https://www.ruby-forum.com/u/aaronpowell)\
**Post date:** [June 3, 2009, 6:01pm UTC](https://www.ruby-forum.com/t/nfc-1-0-0-released/169316/9 "2009-06-03T18:01:32Z")

</div>

Ryan D. wrote:

> On Jun 2, 2009, at 21:16 , Suraj K. wrote:
> 
> > Eric H. wrote:
> > 
> > > You have to require ‘nfc’ to get the autoload, so this won’t work.
> > 
> > I beg to differ; you need not require() before using autoload():
> 
> yes… but you have to put that autoload SOMEWHERE. Otherwise, what’s  
> the point? You should have been able to intuit that eric understood  
> this by stating “adding two files to do this is far lamer than  
> Singleton”.

Ah, I see now.

> I believe it is fair to say at this point that nobody involved with  
> nfc cares about “improving” the API as you’re suggesting. There isn’t  
> anything wrong with typing “instance”. As Eric stated,

Alright.

> if you’ve got such a boner for autoload, you’re welcome to fork.

Such harsh words! You could have stopped at the previous sentence; your  
point has already been made. This remark only adds hostility; a poison  
coating for your arrows.

Please remember MINSWAN. ☹

---

<div class="post-metadata">

**Author:** ![aaronpowell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7bcc69/32.png) [@aaronpowell](https://www.ruby-forum.com/u/aaronpowell)\
**Post date:** [July 4, 2009, 9:00am UTC](https://www.ruby-forum.com/t/nfc-1-0-0-released/169316/10 "2009-07-04T09:00:39Z")

</div>

I’m really intrigued by this gem, and have been trying to get it to  
work. Unfortunately, I keep running aground with the following error  
(s):

/opt/local/lib/ruby/gems/1.8/gems/ffi-0.3.5/lib/ffi/library.rb:  
18:in `ffi_lib': Could not open any of [nfc] (LoadError) from /opt/local/lib/ruby/gems/1.8/gems/nfc-1.0.0/lib/nfc/lib_nfc.rb:6 from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb: 31:in`gem\_original\_require’  
from /opt/local/lib/ruby/vendor\_ruby/1.8/rubygems/custom\_require.rb:  
31:in `require' from /opt/local/lib/ruby/gems/1.8/gems/nfc-1.0.0/lib/nfc.rb:2 from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb: 36:in`gem\_original\_require’  
from /opt/local/lib/ruby/vendor\_ruby/1.8/rubygems/custom\_require.rb:  
36:in `require’  
from nfctest.rb:2

Perhaps it’s obvious to more experienced devs, but after much Googling  
and reading to figure it out, I’m stumped. Anyone?

Thanks,  
–T

---

<div class="post-metadata">

**Author:** ![aaronpowell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7bcc69/32.png) [@aaronpowell](https://www.ruby-forum.com/u/aaronpowell)\
**Post date:** [July 4, 2009, 9:21am UTC](https://www.ruby-forum.com/t/nfc-1-0-0-released/169316/11 "2009-07-04T09:21:06Z")

</div>

On Jul 4, 2009, at 00:00 , Reverend Ted wrote:

> I’m really intrigued by this gem, and have been trying to get it to  
> work. Unfortunately, I keep running aground with the following error  
> (s):
> 
> /opt/local/lib/ruby/gems/1.8/gems/ffi-0.3.5/lib/ffi/library.rb:  
> 18:in `ffi\_lib’: Could not open any of [nfc] (LoadError)

nfc (the gem) uses ffi to attach to a C library of the same name. You  
need this installed if it doesn’t ship with the gem (which it prolly  
won’t, otherwise why bother with ffi?).

---

<div class="post-metadata">

**Author:** ![aaronpowell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7bcc69/32.png) [@aaronpowell](https://www.ruby-forum.com/u/aaronpowell)\
**Post date:** [July 4, 2009, 9:26am UTC](https://www.ruby-forum.com/t/nfc-1-0-0-released/169316/12 "2009-07-04T09:26:22Z")

</div>

On Sat, Jul 04, 2009 at 04:00:06PM +0900, Reverend Ted wrote:

> 31:in `require' from /opt/local/lib/ruby/gems/1.8/gems/nfc-1.0.0/lib/nfc.rb:2 from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb: 36:in `gem\_original\_require’  
> from /opt/local/lib/ruby/vendor\_ruby/1.8/rubygems/custom\_require.rb:  
> 36:in `require’  
> from nfctest.rb:2
> 
> Perhaps it’s obvious to more experienced devs, but after much Googling  
> and reading to figure it out, I’m stumped. Anyone?

Make sure to read the section under INSTALL:

[GitHub - tenderlove/nfc: NFC is a ruby wrapper for the Near Field Communication library. · GitHub](http://github.com/tenderlove/nfc/tree/master)

You need to have libnfc installed, and make sure that the dylib (or so)  
is in your LD\_LIBRARY\_PATH.

---

<div class="post-metadata">

**Author:** ![aaronpowell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7bcc69/32.png) [@aaronpowell](https://www.ruby-forum.com/u/aaronpowell)\
**Post date:** [June 3, 2009, 10:54pm UTC](https://www.ruby-forum.com/t/nfc-1-0-0-released/169316/13 "2009-06-03T22:54:49Z")

</div>

On Jun 3, 2009, at 09:01 , Suraj K. wrote:

> > if you’ve got such a boner for autoload, you’re welcome to fork.
> 
> Such harsh words! You could have stopped at the previous sentence;  
> your  
> point has already been made. This remark only adds hostility; a  
> poison  
> coating for your arrows.

I assure you that hostility would be offering you MY boner if you  
didn’t like the current implementation.

---

<div class="post-metadata">

**Author:** ![aaronpowell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7bcc69/32.png) [@aaronpowell](https://www.ruby-forum.com/u/aaronpowell)\
**Post date:** [July 4, 2009, 12:11pm UTC](https://www.ruby-forum.com/t/nfc-1-0-0-released/169316/14 "2009-07-04T12:11:06Z")

</div>

On Jul 4, 9:20 am, Ryan D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Jul 4, 2009, at 00:00 , Reverend Ted wrote:
> 
> nfc (the gem) uses ffi to attach to a C library of the same name. You  
> need this installed if it doesn’t ship with the gem (which it prolly  
> won’t, otherwise why bother with ffi?).

Thanks, Ryan. I had the C library in place. Aaron P.'s PATH  
leads me to the fix.  
T

---

<div class="post-metadata">

**Author:** ![aaronpowell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7bcc69/32.png) [@aaronpowell](https://www.ruby-forum.com/u/aaronpowell)\
**Post date:** [July 4, 2009, 12:30pm UTC](https://www.ruby-forum.com/t/nfc-1-0-0-released/169316/15 "2009-07-04T12:30:58Z")

</div>

On Jul 4, 9:25 am, Aaron P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Make sure to read the section under INSTALL:
> 
> [GitHub - tenderlove/nfc: NFC is a ruby wrapper for the Near Field Communication library. · GitHub](http://github.com/tenderlove/nfc/tree/master)
> 
> You need to have libnfc installed, and make sure that the dylib (or so)  
> is in your LD\_LIBRARY\_PATH.

Aaron:  
Thanks for the reply. That gave me enough to get there.

I document the solution for anyone coming along looking for it:

MacOS uses a different environment setting from LD\_LIBRARY\_PATH.  
Instead it uses DYLD\_LIBRARY\_PATH. (Try ‘man dyld’ at the command line  
to learn more about this.)

To enable the nfc gem to find libnfc, you must ‘export  
DYLD\_LIBRARY\_PATH=/path/to/libnfc-1.1.0:$DYLD\_LIBRARY\_PATH’

That makes it work for a given Terminal session. You can add the same  
command to your ~/.profile file.

Thanks both to you and Ryan for the quick replies.

Aaron: mail me at ted /at/ touchatag so I can send you a thank you  
gift.

–Ted

---

<div class="post-metadata">

**Author:** ![aaronpowell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7bcc69/32.png) [@aaronpowell](https://www.ruby-forum.com/u/aaronpowell)\
**Post date:** [July 4, 2009, 10:00pm UTC](https://www.ruby-forum.com/t/nfc-1-0-0-released/169316/16 "2009-07-04T22:00:28Z")

</div>

On Sat, Jul 04, 2009 at 07:30:05PM +0900, Reverend Ted wrote:

> I document the solution for anyone coming along looking for it:
> 
> MacOS uses a different environment setting from LD\_LIBRARY\_PATH.  
> Instead it uses DYLD\_LIBRARY\_PATH. (Try ‘man dyld’ at the command line  
> to learn more about this.)
> 
> To enable the nfc gem to find libnfc, you must ‘export  
> DYLD\_LIBRARY\_PATH=/path/to/libnfc-1.1.0:$DYLD\_LIBRARY\_PATH’

Hrm. ffi uses dlopen for loading the dynamic library. The man page for  
dlopen under the searching section indicates that it searches  
LD\_LIBRARY\_PATH, DYLD\_LIBRARY\_PATH, then DYLD\_FALLBACK\_LIBRARY\_PATH.

So either _should_ work (though I haven’t tried).

> That makes it work for a given Terminal session. You can add the same  
> command to your ~/.profile file.
> 
> Thanks both to you and Ryan for the quick replies.

No problem!

> Aaron: mail me at ted /at/ touchatag so I can send you a thank you  
> gift.

Sent. Thank you! 🙂
