Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 418 Vote(s) - 3.58 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What are these strings called? What is squish? Ruby

#1
I found this code:

sql = <<-SQL.squish
UPDATE #{klass.constantize.table_name}
SET uuid = uuid_generate_v4(), updated_at = now()
WHERE id IN (#{group.map(&:id).join(',')})
AND uuid IS NULL
SQL

What is going on here? I assume this is some special kind of string delimiter. What is it called? Is it Ruby specific? What is `squish` doing?
Reply

#2
This is a syntax for a [Here Document](

[To see links please register here]

) (`HereDoc`), which is a multiline string in Ruby.

For example, this:

sql = <<-SQL
UPDATE #{klass.constantize.table_name}
SET uuid = uuid_generate_v4(), updated_at = now()
WHERE id IN (#{group.map(&:id).join(',')})
AND uuid IS NULL
SQL

Will give you an `sql` string variable whose value is literally:

UPDATE #{klass.constantize.table_name}
SET uuid = uuid_generate_v4(), updated_at = now()
WHERE id IN (#{group.map(&:id).join(',')})
AND uuid IS NULL

with all the spaces and newlines preserved.

From the HereDoc docs:

> To call a method on a heredoc place it after the opening identifier

A popular usage of that quote is when you have a long string and you don't want to write it on a single line, and hence use a HereDoc for it, but you still don't want to keep all the newline characters and white spaces that the HereDoc preserves, in which case you can just call [`squish`](

[To see links please register here]

) (which is a method added by Rails) to remove them. For example, this:

sql = <<-SQL.squish
UPDATE #{klass.constantize.table_name}
SET uuid = uuid_generate_v4(), updated_at = now()
WHERE id IN (#{group.map(&:id).join(',')})
AND uuid IS NULL
SQL

Will give you an `sql` string variable whose value is literally:

UPDATE #{klass.constantize.table_name} SET uuid = uuid_generate_v4(), updated_at = now() WHERE id IN (#{group.map(&:id).join(',')}) AND uuid IS NULL

With all consequent newline characters and spaces squished into one whitespace.
Reply

#3
`String#squish` comes from Rails and means that resulting inline string is without multiple `\n` and `\s`.
From [docs][1]:

> Returns the string, first removing all whitespace on both ends of the
> string, and then changing remaining consecutive whitespace groups into
> one space each.


[1]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through