How to use Proc/lamba returned from a method in Ruby?

0 votes

I am unable to use the Proc returned by valid_transaction as argument in the select filter. This is the code I am using.

require 'json'


module Electrum

  class History

    def self.valid_transaction

      lambda { |tx| tx["date"] == "----" }

    end


    def self.list

      JSON::parse `electrum history`

    end


    def self.confirmed

      list.reject { |tx| tx["date"] == "----" }

    end


    def self.unconfirmed

      list.select(&:valid_transaction)

    end

  end

end
Aug 24, 2018 in Blockchain by slayer
• 29,170 points
45 views

1 answer to this question.

0 votes
You need to remove the colon:

list.select(&valid_transaction)

The & syntax is used to pass a lambda or proc to a method that is expecting a block. That's what you need here.

With a colon, the meaning of that expression is different:

list.select(&:valid_transaction)

is equivalent to this:

list.select { |tx| tx.valid_transaction }

And that’s why you’re code wasn’t working as expected.
answered Aug 24, 2018 by digger
• 26,550 points

Related Questions In Blockchain

+1 vote
2 answers

How to return value from a chaincode in Hyperledger Fabric?

Hyperledger Fabric supports only 2 types of ...READ MORE

answered Jun 13, 2018 in Blockchain by Perry
• 17,020 points
921 views
0 votes
1 answer

How to use ethereum contract's state changing method in javascript?

You'll find that the message is indeed ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
38 views
+1 vote
2 answers
0 votes
1 answer

How to make sure transactions take no fee in a private Ethereum blockchain?

In a private ethereum network you have ...READ MORE

answered Mar 26, 2018 in Blockchain by Christine
• 15,790 points

edited Mar 26, 2018 by Christine 122 views
+1 vote
3 answers

Removing double quotes from a string from JSON response in PHP

Just remove the json_encode call, and it should work: $resp ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 26,550 points
4,310 views
0 votes
1 answer
0 votes
1 answer

Sending keep-alive packet, bitcoin.

You can use Websocket Eventmachine Client (https://github.com/imanel/websocket-eventmachine-client) gem to ...READ MORE

answered Aug 20, 2018 in Blockchain by digger
• 26,550 points
54 views
0 votes
1 answer
0 votes
1 answer

How i can use nodejs to watch transactions in bitcoin network?

you can use  const Socket = require('blockchain.info/Socket'); const mySocket ...READ MORE

answered Jul 9, 2018 in Blockchain by digger
• 26,550 points
53 views