V
V
Vladislav2016-11-04 20:35:12
ruby
Vladislav, 2016-11-04 20:35:12

Problems with parsing ruby ​​syntax, what does it mean?

There is a function in Ruby:

def signature h
    sorted_params = h.to_a.sort{|x, y| x[0].to_s <=> y[0].to_s} #1
       s = ""
       sorted_params.each{|k, v| s += "#{k}=#{v}"} #2
       s += "62f8"
       sig = Digest::MD5.hexdigest(s)
       sig
  end

an object of a similar form h = {e: "aaa", b: "aaa"} is passed to the f- th,
as I understand it in the first line # 1, this object is converted into an array, then assigned in a sorted form.
So I didn’t understand a little how to get the same line in php?
Does line #2 just concatenate key-value? without any spaces?
And why there is no return word in ruby, as I understand it, the value at the end is returned here.
Yes, thanks, I already found out this by practical means)
Such a question remained when you glue it into a string, in PHP boolean variables are represented as 1, and in ruby ​​as "true"
because of this, md5 is different, how can this be fixed?
____
Thank you all, figured out
json_encode($bool)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2016-11-04
@Div100

Sorted by key: php.net/manual/en/function.ksort.php Spliced
​​into string key1=value1key2=value2key3=value3
Secret key 62f8 added at the end
Considered md5 php.net/manual/en/function.md5.php Must
be watched on the documentation of the payment (apparently) system for which this code, and not in the code itself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question