Skip to content

Instantly share code, notes, and snippets.

View stevencch99's full-sized avatar
🙌
Face the music

Steven C. stevencch99

🙌
Face the music
View GitHub Profile
# 定義一個 Porc 物件把 block 包起來,當呼叫的時候會在裡面做運算並回傳布林值(true or false)
divisible_by_15 = proc { |number| (number % 15).zero? }
divisible_by_5 = proc { |number| (number % 5).zero? }
divisible_by_3 = proc { |number| (number % 3).zero? }
num = 9
case num
# when 會呼叫 divisible_by_15 的 === 方法,將 num 作為引數傳進去
# divisible_by_15 === 9
# Use Proc.new to capture a block passed to a method without an ecplicit block argument
def make_proc
Proc.new
end
double = make_proc { |number| number * 2}
// Example in JavaScript
let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
function isEven(x){
return x % 2 === 0;
}
let evenNumbers = numbers.filter(isEven);
// 2 4 6
# 創造 Proc 物件並指派給變數 double
double = Proc.new { |number| number * 2 }
# shorthand
double = proc { |number| number * 2 }
# 作為參數傳入另一個方法
def make_proc(&block)
block
end
double-then-square(x) = square(double(x))
double-then-square(2) = 16
double-then-square(3) = 36
@stevencch99
stevencch99 / double.rb
Last active January 5, 2020 11:57
sample ruby-double
# double the number
def double(x)
x * 2
end
double(2) # => 4
double(3) # => 6
double(4) # => 8
# squares the number
/* Add the subtle gradient to the editor background */
.monaco-editor {
background-color: transparent !important;
/* 背景顏色預設值,先註解起來留著 */
/* background-image: linear-gradient(to bottom, #2a2139 75%, #34294f); */
/* 修改成自己喜歡的背景顏色 */
background-image: linear-gradient(to bottom, hsla(209, 100%, 16%, 0.836) 50%, #003c44);
}

我所認知的 Ruby 程式語言

首先請容我簡單介紹一下自己的經歷,高中讀電機,大學念冷凍空調與能源系,畢業後即投身於空調工程相關領域,到現在大約有8年相關經驗。

回顧整個生命軌跡,距離程式語言最靠近的時候,也許是大學上課時漫不經心把玩 Visual Basic 那會兒,雖然喜歡打電動,但始終也無法將熱忱投射到程式設計這件事上。

當時的我想像,寫程式就是要每天釘在座位上十幾小時,從上千行難懂的文字和演算法中除錯,工時長壓力大,不難理解為什麼傳說中工程師過勞死的比例這麼高。

但某次在和一位學經歷相近的前輩閒聊中,我聽說了有 Ruby on Rails 這門學問,說是她不如你想像中的困難,並且可以幫助你快速將一些想法實踐並上線投入市場。這位前輩在很短的時間內自學有成,並找到理想的工作。從他的經驗聽起來,這個領域的人們似乎對自己的工作都充滿熱情。

puts "練習 1:請印出從 1 到 100 之間所有的單數。"
puts " # Ans. 1.1"
(1..100).each do |i|
p i if i.odd?
end
p "======================================"
puts " # Ans. 1.2"
p [*1..100].select { |i| i.odd? }
p "======================================"
@stevencch99
stevencch99 / trello-cards-from-csv.rb
Created November 22, 2017 11:46 — forked from joshmcarthur/trello-cards-from-csv.rb
A Ruby script to import Trello cards from a CSV file
#!/usr/bin/env ruby
# You can skip this bit if you wish - you will need the 'ruby-trello' gem installed, and
# optionally, 'foreman' to run the script with.
require 'bundler/setup'
Bundler.require
require 'trello'
require 'csv'