Running methods on a class in gem

I have installed a gem "Rubygsm and dependencies"
I have the send sms working via the gem

The following code is from the gem core file for receiving an sms:

  # call-seq:
  # receive(callback_method, interval=5, join_thread=false)

Craig Leppan wrote in post #972958:

I have installed a gem "Rubygsm and dependencies"
I have the send sms working via the gem

The following code is from the gem core file for receiving an sms:

  # call-seq:
  # receive(callback_method, interval=5, join_thread=false)
  #
  # Starts a new thread, which polls the device every _interval_
  # seconds to capture incoming SMS and call _callback_method_
  # for each, and polls the device's internal storage for incoming
  # SMS that we weren't notified about (some modems don't support
  # that).
  #
  # class Receiver
  # def incoming(msg)
  # puts "From #{msg.from} at #{msg.sent}:", msg.text
  # end
  # end

This is showing you an example of a custom class that you are expected
to write. Say in a file called receiver.rb.

  # # create the instances,
  # # and start receiving
  # rcv = Receiver.new
  # m = Gsm::Modem.new "/dev/ttyS0"
  # m.receive rcv.method :incoming
  #
  # # block until ctrl+c
  # while(true) { sleep 2 }

This is a script that uses the Receiver class. This code can be placed
at the end of the receiver.rb file somewhere after declaring and
implementing your Receiver class (just like the example here is
showing). Or it could exist in it's own file that requires receiver.rb
at top.

The last line of this file will loop indefinitely with a two second
sleep between each loop.

Use ctrl+c to stop the program as shown above.

Note: I don't see it shown here but you will need to require the gem
somewhere at the very top of receiver.rb. Something like:

require 'rubygems'
require '<whatever the name of the file is for Gsm::Modem>'

In case you'll be using this inside a Rails project somehow then adding
the gem to your Gemfile should be sufficient to use the GSM::Modem class
I believe.

Great :slight_smile:
I will give it a try Robert, thanks for the help