i i q - ror
1.
ror - ruby on rails is a open source, server side application framework that is written in the object oriented programming langugae ruby .
2.
spring - with spring does not need to restart the server when changes .spring is a preloader of applications to speed up the development.
3.
assoications rails -
- One-to-one: A relationship in which one object is linked to only one other object
- One-to-many: A relationship in which one object can be related to many other objects
- Many-to-many: A relationship in which an instance of the first type of object is linked to one or more instances of a second type of object, and an instance of a second type of object is linked to one or more instances of the first type of object
4.
what is splat operator -
Developers use the splat operator (*) when they pass arguments to a method but don’t want to specify how many arguments they are passing. Candidates may mention that there are two types of splat operators – the single splat (*) and the double splat (**).
5. active record -
6.
Is Ruby a flexible language? Why, or why not?
Ruby is considered a pretty flexible language, as it allows a developer to modify code's contents at any time. In this way, it does not limit the programmer, who can easily make any changes whenever they want.
7.
what are closures in rails ?
closure can be treated like a variable that can be assigned to another variable or can be pass to any function as an argument
.....................................................................
8. what is the difference between class and library ::
Link :: https://www.baeldung.com/cs/framework-vs-library
.....................................................................
9. what is garbage collections in ruby on rails ::
Good link :: https://stackify.com/how-does-ruby-garbage-collection-work-a-simple-tutorial/
in ruby like different high level programing languages does not force you to manage memory . this feature is called garbage collection or GC and it is free in the memory .
garbage collection ::: this is the complete memory management system in ruby. since everything in ruby is the object so garbage collection is all about object management.
1. free list : first allocating memory takes some time , so ruby pre-allocates throusands of objects to have them ready when you need them. this is called the free list .
2. mark phase :: in the mark phase ruby crawls through all objects and marks the ones that are still in use.
3. sweep phase :: ruby goes through all objects again. clean up the unmarked objects and return them to the free list .
4. tri-color-mark-and-sweep-object :: this divide the object in 3 categories - white , gray and black::
white objects : white objects are unmarked possibly collection objects .
gray objects : gray objects are marked but may have references to white objects.
black objects : finally black objects have been marked and definately do not point to any white objects .
.....................................................................
10. what is mocks and stubs in ruby on rails ::
.....................................................................
:: :: Some Others :: ::
...........................................................................................................................
8.
what is proc , lambda and block ?
lambda :
in ruby lambda is an object similiar to proc . unlike a proc a lambda requires the specific no of arguments passed to it and it return to its calling method rather than returning immediately.
proc :
in ruby proc is an instance of the proc class and is similiar to the block . a proc is a ruby object which can be stored in the variable and therefore resused many times throughout a program .
yield :
in ruby the yield keyword is used to transfer control from a method to a block and then back to the method since executed.
.call :
in ruby the proc and lambda can be called directly using the .call method
.collect :
.collect array method takes a block and applies the expression in the block to every element of an array .
block :
a block has the same thing as the method but it does not belong to an object . blocks are closures in other programing languages. block can accept arguments and return value. block does not have their own name .
1. block can accept arguments and return a value .
2. block does not have their own name
3. block consists of chunk of code
4. to call a block within a method with a value use yield statement is used .
5. block can be called just like methods from inside the method that is passed to
syntax of block ::
1. block_name do
#statement-1
#statement-2
.
.
end
2. block_name { #statements_to_be_executed }
Ruby proc ::
- square = Proc. new { |x| x ** 2 } # A proc is defined by calling Proc. new followed by a block.
- [2, 4, 6]. collect!( &square) # When passing a proc to a method, an & is used to convert the proc into a block.
- puts [2, 4, 6]. collect!( &square) # => [4, 16, 36]
............................................................................
:: important ruby operators and methods ::
................................................................................
1. ruby combined comparison operator
2. ruby method splat
3. ruby block parameter
4. ruby return
5. ruby sort method
6. ruby method parameters and aguments
7. ruby method
8. ruby block
........................................................................................
imp link ::::: https://www.codecademy.com/learn/learn-ruby/modules/learn-ruby-blocks-and-sorting-u/cheatsheet
............................................................................
what is ruby combined comparison operator :: VVVVVVV.IMP
combined comparion operator :: <=>
In Ruby, the combined comparison operator,
<=>, also known as the spaceship operator is used to compare two objects. It returns 0 if the first operand equals the second, 1 if the first operand is greater than the second, and -1 if the first operand is less than the second.............................................................................
what is ruby method parameter and arguments ::
In Ruby, parameters are placeholders for real values or arguments passed into a method when it is called. When calling a method that requires parameters, arguments (ie. real values) must be passed in for those parameters.
def square(num) # num is the parameterputs num ** 2endsquare(5) #5 is the argument#Output => 25
.........................................................................................
ruby sort method ::
In Ruby, the
.sort array method is used to sort items in an array in ascending order (least to greatest).my_array = [3, 4, 8, 7, 1, 6, 5, 9, 2]my_array.sort!#Attaching an ! to the end of .sort or any other Ruby method modifies the original array.print my_array# => [1, 2, 3, 4, 5, 6, 7, 8, 9]#If you didn't use !, print my_array returns the original array.
.........................................................................................
ruby method splat ::
In a Ruby method, a splat (
*) operator is used to indicate that a parameter can have an unknown number of arguments.def extra_curriculars(*clubs)clubs.each { |club| puts "After school, I'm involved with #{club}" }endextra_curriculars("chess club", "gymnastics", "anime club", "library services")
Comments
Post a Comment