This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Cat | |
attr_reader :color, :breed, :name | |
# There is no need for a separate attr_writer and separate attr_reader for name because attr_accessor can combine those methods into one (DRY) | |
# attr_writer :name | |
attr_accessor :name | |
def initialize(color, breed) | |
@color = color # Instances variables are available to other methods inside of this class. This is unlike local variables, which only exist inside the method they're called in. | |
@breed = breed | |
@hungry = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
str.is_a?(Object) | |
str.class | |
# here we extend Ruby's string class meaning that all strings in the environment will belong to this class | |
class String | |
def star | |
self + " *" | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ends the game | |
def end_game | |
puts "\nBye!" | |
end | |
# the game which recursively calls itself until user presses "X" to call end_game and finish the game | |
def game | |
puts "==============================\nPlease choose one from the following:\n(R) Rock\n(P) Paper\n(S) Scissors\n(X) End game\n\n" | |
user_turn = gets.chomp.capitalize! | |
if user_turn != "R" && user_turn != "P" && user_turn != "S" && user_turn != "X" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AddAdminFlagToUsers < ActiveRecord::Migration[5.1] | |
def change | |
add_column :users, :admin, :boolean, default: false, null: false | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This file is auto-generated from the current state of the database. Instead | |
# of editing this file, please use the migrations feature of Active Record to | |
# incrementally modify your database, and then regenerate this schema definition. | |
# | |
# Note that this schema.rb definition is the authoritative source for your | |
# database schema. If you need to create the application database on another | |
# system, you should be using db:schema:load, not running all the migrations | |
# from scratch. The latter is a flawed and unsustainable approach (the more migrations | |
# you'll amass, the slower it'll run and the greater likelihood for issues). | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h2>Sign up</h2> | |
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> | |
<%= devise_error_messages! %> | |
<div class="field form-group"> | |
<%= f.text_field :first_name, autofocus: true, class: "form-control", placeholder: 'First name' %> | |
</div> | |
<div class="field form-group"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UsersController < ApplicationController | |
before_action :set_user, only: [:show, :edit, :update, :destroy] | |
before_action :authenticate_user!, except: [:show, :index] | |
load_and_authorize_resource | |
# GET /users | |
# GET /users.json | |
def index | |
@users = User.all | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rails_helper' | |
describe Product do | |
context "when the product has comments" do | |
let(:product) { Product.create!(name: "race bike") } | |
let(:user) { User.create!(first_name: "John", last_name: "Smith", email: "[email protected]", password: "password123") } | |
before do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
namespace Roman | |
{ | |
internal class Program | |
{ | |
private static void Main(string[] args) | |
{ | |
// Decode and print the numerals. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Customer | |
{ | |
string CustomerName; | |
// Constructor for Customer class | |
public Customer(string Name) | |
{ | |
CustomerName = Name; | |
} | |
} |