Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Ruby
Ruby
  1. Mastering Code Output ด้วย Awesome Print: Ruby Gem สำหรับ Logging ที่สะอาด อ่านง่าย

    awesome_print gem format output ใน irb/pry ให้อ่านง่าย สีสัน สวยงาม Printing Awesomely อ่าน source code หาว่าทำงานยังไง เริ่มจาก project structure แล้วถามคำถาม: awesome_print เปลี่ยน output ของ pry อย่างไร? Loading Awesome Print require awesome_print AwesomePrint.pry! หา pry! method: def pry! Pry.

  2. ปลดล็อก 7 Ruby Methods อันทรงพลัง เพิ่มคุณภาพและประสิทธิภาพโค้ด

    ใช้เมธอดที่ถูกต้อง ประหยัดงาน โค้ดดีขึ้นทั้ง performance และ quality 7 เมธอดที่ควรรู้: 1. Integer#digits (Ruby 2.4+) แยกหลักเลขของ Integer (ก่อนหน้า: to_s.chars.map(&:to_i).reverse) 123.digits # [3, 2, 1] (reverse order!) หมายเหตุ: Fixnum/Bignum deprecated รวมเป็น Integer 2. The Tap Method สร้างอ็

  3. เชี่ยวชาญ Ruby's Array#zip: จับคู่และเปรียบเทียบ Array อย่างมีประสิทธิภาพ

    ต้องการเปรียบเทียบ 2 arrays element-by-element หาความต่าง หาค่าสูงสุดแต่ละ index หรือ merge keys+values เป็น hash Hard way ใช้ map.with_index ยุ่งยาก a = [1,2,3,4,5]; b = [1,2,3,6,8] c = a.map.with_index { |_, idx| [a[idx], b[idx]] } # [[1,1],[2,2],[3,3],[4,6],[5,8]] Array#zip Way a.zip(b) # [[1,1]

  4. สร้าง Link Shortener App ด้วย Ruby & Sinatra: Step-by-Step Tutorial

    โปรเจกต์เล็กฝึก Ruby skills: สร้าง Link Shortener แมป short code (เช่น eKBRm2tTUF) → original URL First Steps ใช้ Sinatra (no setup) และ PStore (file-based database จาก stdlib) แทน SQL require sinatra get /:url do The URL is #{params[:url]} end get / do Send a POST request to register a new URL. end

  5. Atom Editor สำหรับ Ruby: Top Plugins & Essential Shortcuts

    Atom packages (plugins) ช่วยเพิ่ม productivity มีเยอะมาก ตัวไหนควรใช้? พร้อม keyboard shortcuts ที่มีประโยชน์ Best Atom Packages ติดตั้งจาก Settings (Ctrl+,) → Install tab 1. Atom Runner รันโค้ดใน editor เอง output แสดง split window ด้านขวา (หรือล่างใน Atom 1.17+) ติดตั้งค้นหา atom runner กด Alt+R (

  6. เชี่ยวชาญ Prefix Trees (Tries) ใน Ruby: Implementation & Practical Uses

    Prefix tree (Trie) = data structure จัดระเบียบ word list หาคำที่ขึ้นต้นด้วย prefix เร็ว (เช่น ca → cat, cape) Prefix Tree Implementation Node class: value (char), word (true/false = valid word), next (array ของ Node ถัดไป) class Node attr_reader :value, :next attr_accessor :word def initialize

  7. เข้าใจ Ruby's Hidden Errors: ทำไมเกิดขึ้นและจัดการอย่างไร

    Ruby ซ่อน errors/exceptions บางอย่าง ไม่ให้คุณเห็น บางครั้งมีประโยชน์ (เช่น Kernel#loop หยุดเมื่อ StopIteration) แต่บางครั้งทำให้ debug ยาก Method class MyObject attr_accessor :value include Comparable def initialize(value); @value = value; end def <=>(other) raise ArgumentError,

  8. คู่มือสมบูรณ์ Ruby's Nil Object: คืออะไร ทำงานอย่างไร ทำไมจึงสำคัญ

    nil คือ special Ruby object แทนค่า empty หรือ default เป็น falsy value (ทำงานเหมือน false ใน conditional) มีเพียง หนึ่ง nil object object_id = 4 (หรือ 8 ใน 64-bit) nil.object_id # 4 Where Do Nil Values Come From? หลายเมธอดคืน nil เมื่อหาค่าไม่เจอ: product not found, array index out of bounds, hash

  9. คู่มือ Ruby String Methods ขั้นสูง: Mastering Text Manipulation

    String คือลำดับตัวอักษร เป็นอ็อบเจ็กต์มีเมธอดมากมาย คู่มือเมธอดที่ใช้บ่อยและมีประโยชน์ 1. String Length ruby.size # 4 (length เหมือนกัน) 2. Check Empty String .empty? # true # blank = empty หรือแค่ whitespace 3. String Interpolation name = Jesus puts Hello #{name} puts The total is #{1+1} # code

  10. เชี่ยวชาญ Functional Programming ใน Ruby: คู่มือสมบูรณ์

    Functional programming (FP) คือ paradigm ที่หลีกเลี่ยงการเปลี่ยน state และเขียน pure functions ข้อมูลทั้งหมด Immutable (Haskell) variables เหมือนคณิตศาสตร์: กำหนดค่าแล้วเปลี่ยนไม่ได้ Benefits Of Functional Programming Immutability = ข้อดีหลัก เพราะ mutable data นำไปสู่ subtle bugs ที่ยากต่อการติดตาม

  11. เข้าใจ Ruby Symbols: นิยาม การใช้งาน และความแตกต่างสำคัญ

    Symbol เขียนแบบ :testing บางคนสับสนกับ variables แต่มัน คล้าย String มากกว่า ความแตกต่าง Symbols vs Strings Strings ใช้กับ Data (ข้อมูล) Symbols ใช้เป็น Identifiers (ตัวระบุตัวตน) นี่คือความแตกต่างหลัก Symbols ไม่ใช่แค่ string อีกประเภท มีวัตถุประสงค์ต่างกัน When to Use Symbols (เมื่อไหร่ควรใช้ Symb

  12. คู่มือขั้นตอน: สร้าง Ruby C Extension เพื่อ Performance และ Integration

    เขียน C extension เรียก Ruby จาก C เหมาะสำหรับ optimize เมธอดสำคัญด้วยความเร็ว C หรือ interface กับ C library (ทางเลือกอื่น: FFI module) Your First C Extension สร้าง extconf.rb: require mkmf create_header create_makefile foobar รัน ruby extconf.rb ได้ Makefile, extconf.h สร้าง foobar.c: #include rub

  13. เชี่ยวชาญ Time Complexity: คู่มือครบครันสำหรับ Ruby Developers

    Time complexity ช่วยเห็นว่า ทำไมอัลกอริทึม/โปรแกรมจึงช้า และแก้ไขอย่างไร ไม่ต้องมี degree CS ก็เข้าใจได้ Slow vs Fast ไม่ได้ถามว่า 150ms ช้าหรือเร็ว แต่ถามว่า เมื่อ input size เพิ่มขึ้น performance จะเปลี่ยนอย่างไร Input size = ขนาดอาร์กิวเมนต์ (ความยาว string, ขนาด array) Big O Notation จัดกลุ่มอัล

  14. Profiling Ruby Memory Allocation ด้วย Google TCMalloc

    Ruby ขอหน่วยความจำเป็น chunks เรียกว่า pages ใช้ malloc จาก OS มี alternative implementations เช่น Googles tcmalloc (ส่วนของ Google Performance Tools) ใช้ LD_PRELOAD แทนที่ system malloc LD_PRELOAD=/usr/lib/libtcmalloc.so ruby -e puts 123 Enabling The Profiler เปิด profiler ด้วย HEAPPROFILE: LD_PREL

  15. สร้าง Memory Leak ใน Ruby โดยเจตนา: สาธิตปฏิบัติจริง

    บทความส่วนใหญ่สอนหา memory leak แต่นี้จะสอน สร้าง เพื่อรู้จักลักษณะ A Simple Leak (Leak แบบง่าย) เพิ่มอ็อบเจ็กต์ใหม่เข้า Array ตลอดเวลา: a = [] b = {} loop { sleep(1) 10_000.times { a << abc } puts GC.stat(b)[:heap_live_slots] } นับอ็อบเจ็กต์เพิ่มขึ้นเรื่อยๆ เพราะ GC ไม่เก็บได้ (ถูก refere

  16. เพิ่มความสามารถให้ Ruby Objects ด้วย Decorator Pattern: คู่มือปฏิบัติ

    Decorator pattern ช่วย เพิ่มความสามารถใหม่ให้อ็อบเจ็กต์ โดยไม่ต้องเปลี่ยนคลาส Logging & Performance ใช้ rest-client ทำ HTTP request ต้องการเพิ่ม logging แต่ไม่แก้ RestClient module: module LogHTTPRequest def get(url) puts Sending Request For #{url} super end end ใช้ extend เพิ่ม logg

  17. เชี่ยวชาญ Strategy Pattern ใน Ruby: สลับอัลกอริทึมไดนามิกและปฏิบัติตาม Open/Closed Principle

    Strategy pattern ช่วยเปลี่ยนอัลกอริทึมหลักภายในเมธอด โดยส่งผ่านคลาสที่ implement อัลกอริทึม แทนที่จะ hardcode ไว้ในคลาส อัลกอริทึม ที่นี่หมายถึงโค้ดลำดับขั้นตอนเพื่อผลลัพธ์ ไม่ใช่แค่ CS algorithms When To Use The Strategy Pattern แก้ปัญหา Open/Closed Principle: Software entities ควร open สำหรับ exte

  18. ยกระดับโค้ด Ruby: เชี่ยวชาญ Cohesion & Coupling สำหรับ OOP Design ที่สะอาด

    Cohesion และ Coupling เป็นหลักการ OOP สำคัญที่สุด 2 ข้อ Cohesion: ความสัมพันธ์ระหว่างเมธอดภายในคลาส ใช้ instance variables/parameters เดียวกัน ทำงานร่วมกันไปเป้าหมายเดียวกัน? หรือแต่ละเมธอดแยกจากกัน? Coupling: คลาสขึ้นกับคลาสอื่นมากแค่ไหน ผูกมัด กันแน่นแค่ไหน และสามารถใช้งานแยกได้ไหม เป้าหมาย: High

Total 654 -คอมพิวเตอร์  FirstPage PreviousPage NextPage LastPage CurrentPage:20/33  20-คอมพิวเตอร์/Page Goto:1 14 15 16 17 18 19 20 21 22 23 24 25 26