The main difference between a block and a function according to your example is that the block works in the context of the calling function.
So, if your example was like this:
def self.do_something(object_id) x = "boogy on" self.with_params(object_id) do |params| some_stuff(params) puts x end end
The code inside the block can refer to the variable x, which was defined outside the block. This is called a closure. You could not do this if you just called the function in accordance with your second example.
Another interesting thing about blocks is that they can influence the control flow of an external function. So you can do:
def self.do_something(object_id) self.with_params(object_id) do |params| if some_stuff(params) return end end
If calling some_stuff inside a block returns a true value, the block will return. This will be returned from the block and from the dosomething method. porkleworkle won't get a way out.
In your examples, you do not rely on any of them, so using function calls is probably much cleaner.
However, there are many situations where using blocks to allow you to take advantage of these things is invaluable.
source share