Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does -%> mean in Ruby on Rails, compared to %> [duplicate]

I've always used <%= some_code %> to insert Ruby into HTML when using Ruby on Rails. I've just noticed that other projects sometimes use <%= some_code -%>.

like image 873
ben Avatar asked Sep 27 '10 06:09

ben


People also ask

What is the difference between the object methods clone and DUP?

In general, clone and dup may have different semantics in descendant classes. While clone is used to duplicate an object, including its internal state, dup typically uses the class of the descendant object to create the new instance. When using dup, any modules that the object has been extended with will not be copied.

What is DUP in Ruby on Rails?

The dup() is an inbuilt method in Ruby returns the number itself.

How do you duplicate an object in Rails?

You generally use #clone if you want to copy an object including its internal state. This is what Rails is using with its #dup method on ActiveRecord. It uses #dup to allow you to duplicate a record without its "internal" state (id and timestamps), and leaves #clone up to Ruby to implement.

What does .first mean in Ruby?

Ruby | Array class first() function first() is a Array class method which returns the first element of the array or the first 'n' elements from the array.


1 Answers

<%= some_code -%> The minus at the end removes the newline. Useful for formatting the generated HTML, while <%= some_code %> does not.

Thanks, Anubhaw

like image 53
Anubhaw Avatar answered Oct 06 '22 00:10

Anubhaw