Coder Social home page Coder Social logo

面試題目參考資料 about ama HOT 1 OPEN

puff-tw avatar puff-tw commented on June 12, 2024
面試題目參考資料

from ama.

Comments (1)

puff-tw avatar puff-tw commented on June 12, 2024

Ruby 題目

  1. 請完成本題實作內容
class Cat
  # 請完成實作
end

kitty = Cat.new("kitty")
puts kitty.name  # 在畫面上印出 kitty 字樣
  1. 假設有個 Hash:
profile = {name: "kk", age: 18}

當執行這行程式:

p profile["name"]

會得到什麼結果? 為什麼?

  1. 如果要在 1 到 100 的數字當中,任意取出 5 個不重複的亂數,你會怎麼做?

class Bank
  def transfer(amount)
    # ...
  end
end

Bank.transfer(10)

上面這段程式碼執行後會發生什麼事?為什麼?如果有錯誤又該如何修正?

  1. 請問以下方法:
link_to "刪除", products_path(product), method: :delete, class: "btn btn-default"

link_to 方法共有幾個參數?為什麼?

  1. 在 Ruby 裡面常會看到冒號的寫法,例如:

有的冒號靠右邊:

class Store
  has_many :products
end

有的冒號靠左邊:

link_to "檢視", books_path(book), class: "btn btn-default"

或是兩邊都有:

user_profile = {name: "kk", age: 18, blood_type: :b_negative}

請問,這三種寫法分別代表什麼意思呢?

Rails 題目

  1. 請簡述 bundle install 指令的用途。

  2. 請說明 rails db:migrate 這個指令的用途是什麼?

  3. 假設某個 Controller 的程式碼如下:

class BooksController < ApplicationController
  def index
    @books = Book.all
  end

  def update
    @book = Book.find_by(id: params[:id])
    @book.update(price: 100)
    redirect_to books_path, notice: "資料更新成功"
  end
end

請問:

  • 第 3 行的 @books 前面的那個 @ 是什麼意思?如果把 @ 拿掉會發生什麼事?
  • 第 7 行以及第 8 行的 @book,如果把 @ 拿掉會發生什麼事?為什麼?

Git 題目

  1. 在你想像中的分支(branch),是個什麼樣子的東西?

  2. 空的資料夾無法被加入 Git 版控,但如果就是想讓這個資料夾留下來,你會怎麼處理?

  3. 如果有些檔案,像是 /config/database.yml 之類比較機密的檔案,不想放在 Git 裡面,你會怎麼做?

額外加分題

在之前的作業中曾寫到:

def odd_number_calculator(n)
  # 實作內容
  [*1..n].select(&:odd?).reduce(:+)
end

puts odd_number_calculator(100) # 得到 2500

上述程式中,第 3 行的select 方法使用 (&:odd?) 以及 reduce 方法後面接了 :+ 的意思是什麼呢?

from ama.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.