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 -%>
.
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.
The dup() is an inbuilt method in Ruby returns the number itself.
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.
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.
<%= some_code -%> The minus at the end removes the newline. Useful for formatting the generated HTML, while <%= some_code %> does not.
Thanks, Anubhaw
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With