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,370 points
680 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,740 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,100 points
2,961 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
1,041 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 1,575 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,740 points
45,226 views
0 votes
1 answer

How do I add multiple recipients for transactions via Blockchain API?

Convert the recipes into JSON objects. x = ...READ MORE

answered Jul 6, 2018 in Blockchain by Perry
• 17,100 points
891 views
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,740 points
908 views
0 votes
1 answer

Cant connect Jsonrpc to bitcoin.

I tried the following code and it ...READ MORE

answered Aug 20, 2018 in Blockchain by digger
• 26,740 points
1,009 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,740 points
1,285 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP