# How to validate the block signature?

**URL:** <https://forum.crystal-lang.org/t/how-to-validate-the-block-signature/4370>\
**Category:** Help & Support\
**Created:** [February 17, 2022, 4:30am UTC](https://forum.crystal-lang.org/t/how-to-validate-the-block-signature/4370 "2022-02-17T04:30:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aravindavk](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/aravindavk/32/1020_2.png) [@aravindavk](https://forum.crystal-lang.org/u/aravindavk)\
**Post date:** [February 17, 2022, 4:30am UTC](https://forum.crystal-lang.org/t/how-to-validate-the-block-signature/4370/1 "2022-02-17T04:30:37Z")

</div>

The following example is working even if the block signature in the second call is different from the definition. Is this expected behaviour or a bug?

```crystal
def hello(&block : String, String -> String)
  puts "---"
  puts typeof(block)
  puts "Before Block"
  puts block.call("1", "2")
  puts "After Block"
end

hello do |first, second|
  "#{first} #{second}"
end

hello do |first|
  "#{first} only"
end

```

Output:

```auto
---
Proc(String, String, String)
Before Block
1 2
After Block
---
Proc(String, String, String)
Before Block
1 only
After Block

```

```nohighlight
$ crystal --version
Crystal 1.3.2 [932f193ae] (2022-01-18)

LLVM: 10.0.0
Default target: x86_64-unknown-linux-gnu

```

---

<div class="post-metadata">

**Author:** ![asterite](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/asterite/32/60_2.png) [@asterite](https://forum.crystal-lang.org/u/asterite)\
**Post date:** [February 17, 2022, 12:14pm UTC](https://forum.crystal-lang.org/t/how-to-validate-the-block-signature/4370/2 "2022-02-17T12:14:04Z")

</div>

This is expected behavior. The caller can omit block arguments but not add extra ones. The reason is that we want to allow things like this:

```crystal
3.times do
  puts "Hello!"
end

10.times do |i|
  puts "#{i} **2 = #{i** 2}"
end 

```

That is, an argument is always given to the block, but the caller might choose to omit it.

A follow up question is: what API are you trying to achieve?

---

<div class="post-metadata">

**Author:** ![aravindavk](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/aravindavk/32/1020_2.png) [@aravindavk](https://forum.crystal-lang.org/u/aravindavk)\
**Post date:** [February 17, 2022, 1:58pm UTC](https://forum.crystal-lang.org/t/how-to-validate-the-block-signature/4370/3 "2022-02-17T13:58:55Z")

</div>

That makes sense. Thanks.

> A follow up question is: what API are you trying to achieve?

API is not broken, it was just confusion. Now it is clear.

This is used in the [Storage Manager project](https://github.com/kadalu/moana) for Kadalu Storage/GlusterFS. Today I accidentally discovered that all tests passed even without all the block arguments ([GH issue](https://github.com/kadalu/moana/pull/166#pullrequestreview-884854389)).

Example helper to create CLI subcommand: [mgr/src/cmds/helpers.cr](https://github.com/kadalu/moana/blob/main/mgr/src/cmds/helpers.cr#L55-L57)  
and its usage: [mgr/src/cmds/volumes.cr](https://github.com/kadalu/moana/blob/main/mgr/src/cmds/volumes.cr#L20-L38)

---

<div class="post-metadata">

**Author:** ![paulocoghi](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/paulocoghi/32/1429_2.png) [@paulocoghi](https://forum.crystal-lang.org/u/paulocoghi)\
**Post date:** [February 17, 2022, 8:28pm UTC](https://forum.crystal-lang.org/t/how-to-validate-the-block-signature/4370/4 "2022-02-17T20:28:57Z")

</div>

Incredible and very well done project (Kadalu).
