Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
43 Cards in this Set
- Front
- Back
CRUD |
Create, Read, Update and Destroy items for a resource |
|
What is a class? |
classes are a blue-print for constructing computer models for real or virtual objects - classes hold data, have methods that interact with that data, and are used to instantiate objects |
|
5 types of Ruby Variables, how declared? |
Global Variable - $global_variable Instance Variable - @instance_variable Class Variable - @@class_variable Local Variable - lowercase letter or _ Constants - Begin with an uppercase letter. Constants defined within a class / module can be accessed from within that class / module, defined outside a class or module accessed globally |
|
Ruby Pseudo-Variables - what, which |
special variables that have the appearance of local variables but behave like constants self: The receiver object of the current method.true: Value representing true. false: Value representing false. nil: Value representing undefined. __FILE__: The name of the current source file.__LINE__: The current line number in the source file. |
|
Ruby Basic Literals (3) |
Integer Numbers: -2^30 to 2^30-1 or -2^62 to 2^62-1 (fixnum or bignum) Floating Numbers: objects of class Float String Literals: |
|
Integer Number Formats |
optional leading sign, an optional base indicator (0 for octal, 0x for hex, or 0b for binary), followed by a string of digits in the appropriate base0xff #Hexadecimal0b1011 # Binary |
|
Floating Point Formats (4) |
123.4 # floating point value 1.0e6 # scientific notation 4E20 # dot not required 4e+20 # sign before exponential |
|
HTTP Protocol Verbs |
GET PUT (update) POST (create) DELETE |
|
Generate URL from Route Name |
(name)_url: generates a full (absolute) URL including the protocol and server ex. http://localhost:3000/articles/ (name)_path: creates a URL relative to site root ex. /articles/ Add parameter to end: (name)_path(id) ex. article_path(3) gives articles/3 |
|
REST Actions |
Triggered by a request verb and the path -index: Listing resources -show: Displaying a single resource -destroy: Deleting a single resource -new and create: Creating a new resource -edit and update: Changing a single resource |
|
Request Path Format in Rails (Parameters, formats, optional) |
/articles/:id(.:format) colon (:) words name the data in that position access data as params[:id] () show optional part ex. (.:format), params[:format] /articles/16.xml |
|
Routes: Member Action |
A member action will work on just a single resource, as opposed to the collection resources :articles do member do put 'publish' end end |
|
Routes: Collection Action |
A collection action will work as a custom action on a collection of resources resources :articles do collection do put 'publish_all' end end |
|
Nested Resources |
Nest resources inside another resources block resources :articles do resources :comments end |
|
Match Routes (non REST) |
resources :sessions match '/login' => 'sessions#new', as: 'login' match '/logout' => 'sessions#destroy', as: 'logout' :as parameter gives name for route |
|
Root Route (and helper) |
root to: "articles#index" Make sure public/index.html is deleted root_path helper method |
|
Redirection Routes (What? Syntax?) |
Redirect to a new path (ex. change posts to articles) match "/posts/:id" => redirect("/articles/%{id}") |
|
CoffeeScript |
a language that gets compiled to JavaScript makes use of the powerful features of JavaScript without learning the less known features of JavaScript by adding “syntactic sugar” to JavaScript |
|
string interpolation |
full_name = "#{first_name} McFly" Only works with double quotes (for Rails or CoffeeScript) |
|
JavaScript Object |
var myObject = { sayHello : function() { console.log('hello'); }, myName : 'Rebecca' }; myObject.sayHello(); // logs 'hello' console.log(myObject.myName); // logs 'Rebecca' |
|
JavaScript Primitive Data Types (5) |
String: represents sequence of characters e.g. "hello" Number: represents numeric values e.g. 100 Boolean: represents boolean value either false or true Undefined: represents undefined value Null: represents null i.e. no value at all |
|
JavaScript Non-Primitive Data Types (3) |
Object: represents instance through which we can access members Array: represents group of similar values RegExp: represents regular expression |
|
JavaScript Truthy vs. False |
False: undefined, NaN, null, 0, "", and the keyword false Truthy: All else is truthy |
|
Ruby: and vs && operators |
and is the same as && but with lower precedence. They both use short-circuit evaluation. and has lower precedence than =, which is why test_var = true and false would equal true |
|
Ruby Truthy Values |
Nil/ null: False Undefined: Does not exist Boolean: True/False Number: True String: True Object: True |
|
Ruby nil? blank? empty? methods |
nil? defined on all Objects, it only returns true on the nil singleton. blank? defined on all objects too, it returns true if the object also responds to empty? and is empty, or is a false type value (!object is always true). empty? defined on several collection objects, and is true if it has no elements. It is also defined on String. |
|
Ruby function definition (and valid calls) |
times_two 5 times_two(5) times_two (5) the space makes ruby think (5) is an expression, and evaluated it as such. No space is like normal args in any other language |
|
Stabby Lambda |
foo2 = lambda { |arg| arg*2 } foo2 = ->(arg) { arg*2 } foo2.call(5) |
|
Proc vs. Lambda (declare, calling, differences) |
Declare test_proc = Proc.new { |n| n+3 } test_lambda = lambda { |n| n + 3 } test_lambda2 = ->(n) {n + 3} Calling multiply = Proc.new { |x, y| x * y } multiply.call(4, 3) multiply[4, 3] Differences Using an explicit return in a Proc object created with Proc.new (but not lambda) will cause the calling method to return that value. Proc does not care about number of arguments, will create a null value if not enough args. Lambda will throw exception if number of args not correct. |
|
Ruby: p vs puts |
p foo # puts foo.inspect, i.e. it prints the value of inspect instead of to_s, which is more suitable for debugging (because you can e.g. tell the difference between 1, "1" and "2\b1" |
|
(Almost) Everything in Ruby is an Object |
Every Ruby statement or expression evaluates to a single object Class Definition: Evaluate to last expression inside method definition: alwaysevaluate to nil (different than the return value) Conditionals: Evaluate to result of condition, unless no condition is true, or no case statement matched then nil. |
|
Ruby Self |
Is class object inside class itself |
|
Singleton Class |
Ruby classes are actually objects instantiated from the Class class |
|
Create constructor Method |
Method Definition: def initialize(name, creator) @name = name @creator = creator end end calling to create new object: ruby = Language.new("Ruby", "Yukihiro Matsumoto") |
|
Ruby Access Control |
Public Methods: Public methods can be called by anyone. Methods are public by default except for initialize, which is always private. Private Methods: Private methods cannot be accessed, or even viewed from outside the class. Only the class methods can access private members. Protected Methods: A protected method can be invoked only by objects of the defining class and its subclasses. Access is kept within the family. |
|
Create getter/setter methods rails? Separately? |
attr_accessor :my_var # Create both getter and setter methods attr_reader :my_var # Create getter method attr_writer :my_var # Create setter method def age @age end attr_writer :age def age=(value) @age = value end |
|
Equality (4 comparison operators) and applications for different classes |
== generic "equality" Object: true only if obj and other are same String: true if strings match Numeric: Will convert across numeric types (1 == 1.0) === case equality Object: Same as calling ==, but overridden by descendants to provide meaningful semantics .eql? checks value and type For example, 1 == 1.0 evaluates to true, whereas 1.eql?(1.0) evaluates to false Object: True if obj and other refer to same hash key. String: Same length and content .equal? Compares the identity of two objects; i.e., returns true iff both operands have the same object id (i.e., if they both refer to the same object) |
|
Convert to string or number |
Convert to string: 3.to_s # "3" Convert to float: 3.to_f # 3.0 "3.4f".to_f # 3.4 "ff3.4f".to_f # 0.0 Convert to int: 3.4.to_i # 3 (truncates) "3.4".to_i # 3 |
|
Modules (Benefits, Mixin Keywords) |
Benefits: Namespacing Mixins - allow for "multiple inheritance" Mixin Keywords: require 'other_file' # Import other file with module def ClassWithMixin include OtherClassOne include OtherClassTwo end |
|
Super in Ruby |
Allow overridden methods in Ruby to do something in addition to what super class did super will call the same method, but as defined in the super class and give you the result can pass arguments as well def initialize(breed, name) super(breed) @name = name end |
|
singleton class |
When you add a method to a specific object Ruby inserts a new anonymous class into the inheritance hierarchy as a container to hold these types of methods |
|
Singleton Class |
class << foobar a singleton class is being opened for the object to the right of those symbols |
|
Dynamically Vs. Static Type Strongly Vs. Weakly Typed |
A dynamically typed language is a language where the type of a variable can be altered at any time. (It is a string, now it is a Fixnum, now it is a Time object, etc.) A statically typed language is the opposite. (Decide what x is once for all and don’t change your mind!) A strongly typed language is a language that is being strict about what you can do with your typed variables. (Don’t mix them… or I will throw you an error in the face!) A weakly typed language is the opposite. (Do what you want with your different types. Mix them all! We’ll see what happens!) |