This is is likely that you are just publishing a message and then exiting (terminating) the Ruby script before the message is received (asynchronously) via the subscribe callback. To prevent the script from exiting prematurely, set the http_sync parameter to true (false by default) in the publish call:

pubnub =
    subscribe_key: 'sub-key', 
    publish_key: 'pub-key', 
    connect_callback: lambda { |msg| 
            channel: 'my_channel', 
            message: 'Hello from PubNub Ruby SDK!!', 
            http_sync: true)
pubnub.subscribe(channels: 'my_channel') do |envelope|
    puts envelope.result[:data][:messages]