<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Thieu Luu</title>
    <description>The latest articles on DEV Community by Thieu Luu (@tluu5).</description>
    <link>https://dev.to/tluu5</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1230649%2F9f6cd402-5ecd-4146-a7a1-6c909edebea0.jpeg</url>
      <title>DEV Community: Thieu Luu</title>
      <link>https://dev.to/tluu5</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tluu5"/>
    <language>en</language>
    <item>
      <title>First Post for SDF</title>
      <dc:creator>Thieu Luu</dc:creator>
      <pubDate>Tue, 17 Sep 2024 17:02:49 +0000</pubDate>
      <link>https://dev.to/tluu5/first-post-for-sdf-5f1</link>
      <guid>https://dev.to/tluu5/first-post-for-sdf-5f1</guid>
      <description>&lt;p&gt;My elevator speech is "Hi, my name is Brian Luu. My background is in Baking. I was a Lead Bread &amp;amp; Pastry Baker. I have experience in time management, quality control, team building, and leadership under pressure. My question to you is what's your next project that best matches my skills and experiences to help you reach your year-end goal."&lt;/p&gt;

</description>
    </item>
    <item>
      <title>The .each method with do - end blocks and pipes ||</title>
      <dc:creator>Thieu Luu</dc:creator>
      <pubDate>Tue, 16 Jan 2024 20:35:11 +0000</pubDate>
      <link>https://dev.to/tluu5/the-each-method-with-do-end-blocks-and-pipes--hda</link>
      <guid>https://dev.to/tluu5/the-each-method-with-do-end-blocks-and-pipes--hda</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is the .each method?&lt;/strong&gt;&lt;br&gt;
The .each method is an iterator method that is used to iterate over elements in an enumerable object, such as an array, hash, or range. It allows you to perform a specific action for each element in the collection.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using .each with do - end blocks:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Using .each with a do - end block to iterate over elements in an array
numbers = [1, 2, 3, 4, 5]

numbers.each do |num|
  puts num * 2
end

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the do - end block is used to define the code that will be executed for each element in the numbers array. The variable num represents each individual element during each iteration.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using .each with pipes ('||'):&lt;/strong&gt;&lt;br&gt;
You can also use pipes (| |) to specify the block parameters. The following example achieves the same result as the previous one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Using .each with pipes (| |) to iterate over elements in an array
numbers = [1, 2, 3, 4, 5]

numbers.each { |num| puts num * 2 }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the block is written in a single line using braces ({ }). The variable num is still used to represent each element during iteration.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How and when to use .each method?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1) Iterating Over Arrays:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fruits = ["apple", "banana", "orange"]
fruits.each { |fruit| puts "I love #{fruit}" }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2) Iterating Over Hashes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;person = { name: "John", age: 30, city: "New York" }
person.each { |key, value| puts "#{key}: #{value}" }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3) Performing Actions on Each Element:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;numbers = [1, 2, 3, 4, 5]
squared_numbers = []
numbers.each { |num| squared_numbers &amp;lt;&amp;lt; num**2 }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4) Iterating Over a Range:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(1..5).each { |num| puts num }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>beginners</category>
      <category>ruby</category>
    </item>
    <item>
      <title>The .split method</title>
      <dc:creator>Thieu Luu</dc:creator>
      <pubDate>Tue, 16 Jan 2024 20:00:12 +0000</pubDate>
      <link>https://dev.to/tluu5/the-split-method-3m0o</link>
      <guid>https://dev.to/tluu5/the-split-method-3m0o</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is a .split method?&lt;/strong&gt;&lt;br&gt;
The .split method is a string method that is used to split a string into an array of substrings based on a specified delimiter. By default, the delimiter is a space, but you can provide any character or regular expression pattern to determine where the string should be split.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Using .split to split a string into an array of words
sentence = "This is a sample sentence"
words = sentence.split

puts words
# Output: ["This", "is", "a", "sample", "sentence"]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also provide a custom delimiter as an argument to .split. For example, using a comma as the delimiter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Using .split with a custom delimiter (comma)
csv_data = "John,Doe,30"
fields = csv_data.split(',')

puts fields
# Output: ["John", "Doe", "30"]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;How and when to use the .split method?&lt;/strong&gt;&lt;br&gt;
The .split method is particularly useful when working with text data and you need to extract individual components from a delimited string. Here are some common use cases:&lt;/p&gt;

&lt;p&gt;1) Parsing CSV (Comma-Separated Values) Data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;csv_line = "Alice,25,New York"
user_data = csv_line.split(',')

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2) Extracting Paths or File Names:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;file_path = "/path/to/my/file.txt"
parts = file_path.split('/')

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3) Handling Input with Multiple Values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;user_input = gets.chomp
values = user_input.split(',')

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4) Tokenizing Text:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;text = "Tokenizing this text into individual words"
tokens = text.split(' ')

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>beginners</category>
      <category>ruby</category>
    </item>
    <item>
      <title>The .push method</title>
      <dc:creator>Thieu Luu</dc:creator>
      <pubDate>Tue, 16 Jan 2024 19:47:32 +0000</pubDate>
      <link>https://dev.to/tluu5/the-push-method-3phf</link>
      <guid>https://dev.to/tluu5/the-push-method-3phf</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is a .push method?&lt;/strong&gt;&lt;br&gt;
The .push method is a commonly used method for adding elements to the end of an array. It appends the specified object (or objects) to the end of the array and returns the modified array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Creating an array
my_array = [1, 2, 3]

# Using .push to add a new element to the end of the array
my_array.push(4)

puts my_array
# Output: [1, 2, 3, 4]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the .push(4) method is called on the my_array, and the integer 4 is added to the end of the array, resulting in [1, 2, 3, 4].&lt;/p&gt;

&lt;p&gt;You can also use the shorthand notation '&amp;lt;&amp;lt;' for the same purpose:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Using &amp;lt;&amp;lt; to add another element to the end of the array
my_array &amp;lt;&amp;lt; 5

puts my_array
# Output: [1, 2, 3, 4, 5]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;How and when to use the .push method?&lt;/strong&gt;&lt;br&gt;
The .push method is particularly useful when you want to dynamically add elements to an array, especially when working with data that is generated or obtained during the execution of your program. It is commonly used in scenarios like:&lt;/p&gt;

&lt;p&gt;1) Appending Elements in a Loop:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;numbers = [1, 2, 3]
(6..10).each { |num| numbers.push(num) }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2) Building an Array Incrementally:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;result = []
result.push("first")
result.push("second")

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3) Adding Elements Based on Conditions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fruits = ["apple", "banana"]
fruits.push("orange") if some_condition

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4) Dynamic Data Collection:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;user_names = []
user_names.push(get_user_input)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In summary, the .push method is a convenient way to add elements to the end of an array, and you would use it when you need to dynamically expand or modify an array during the course of your program. &lt;/p&gt;

</description>
      <category>beginners</category>
      <category>ruby</category>
    </item>
    <item>
      <title>The Array class</title>
      <dc:creator>Thieu Luu</dc:creator>
      <pubDate>Tue, 16 Jan 2024 19:37:54 +0000</pubDate>
      <link>https://dev.to/tluu5/the-array-class-onh</link>
      <guid>https://dev.to/tluu5/the-array-class-onh</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is an Array?&lt;/strong&gt;&lt;br&gt;
The Array class is an ordered, indexed collection of objects. They are mutable, meaning you can modify the elements of an array after it has been created. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Creating an array with three elements
my_array = [1, "hello", 3.14]

# Accessing elements by index
puts my_array[0]  # Output: 1
puts my_array[1]  # Output: hello
puts my_array[2]  # Output: 3.14

# Modifying elements
my_array[1] = "world"
puts my_array     # Output: [1, "world", 3.14]

# Adding elements to the end of the array
my_array.push("new element")
puts my_array     # Output: [1, "world", 3.14, "new element"]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;How and when to use the Array class?&lt;/strong&gt;&lt;br&gt;
You use the Array class when you need to store and manage a collection of items, especially when the order of elements matters.&lt;/p&gt;

&lt;p&gt;1) List of items: Arrays are great for representing lists of items.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;user_names = ["Alice", "Bob", "Charlie"]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2) Data Transformation: Arrays are often used to transform or process data. You can iterate over the elements and apply operations or filters.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;numbers = [1, 2, 3, 4, 5]
squared_numbers = numbers.map { |num| num**2 }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3) Collection of Objects: Arrays can hold objects of different types, making them versatile for storing heterogeneous collections.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mixed_data = [1, "hello", 3.14, { key: "value" }]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4) Stack or Queue: Arrays can be used as a simple stack or queue where you add or remove elements from one end.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;stack = []
stack.push(1)
stack.push(2)
popped_element = stack.pop

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;5) Working with API Responses: When dealing with API responses, you might use arrays to represent a list of items returned by the API.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;require 'json'
require 'net/http'

api_url = URI.parse('https://api.example.com/data')
api_response = Net::HTTP.get(api_url)
data_array = JSON.parse(api_response)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>beginners</category>
      <category>ruby</category>
    </item>
    <item>
      <title>The .parse method</title>
      <dc:creator>Thieu Luu</dc:creator>
      <pubDate>Sat, 13 Jan 2024 03:32:03 +0000</pubDate>
      <link>https://dev.to/tluu5/the-parse-method-51d8</link>
      <guid>https://dev.to/tluu5/the-parse-method-51d8</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is the .parse method?&lt;/strong&gt;&lt;br&gt;
The .parse method is associated with parsing and converting strings into object. It's very useful when working with API. You often receive data in the form of strings, especially when interacting with web APIs that communicate using JSON (JavaScript Object Notation). The .parse method becomes useful for converting these string representations into useable objects. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;require 'date'

date_string = "2024-01-12"
parsed_date = Date.parse(date_string)

puts parsed_date
# Output: 2024-01-12

require 'json'
require 'net/http'

# Assume you make an API request and get a JSON response as a string
api_url = URI.parse('https://api.example.com/data')
api_response = Net::HTTP.get(api_url)

# Using .parse to convert the JSON string into a Ruby hash
parsed_data = JSON.parse(api_response)

# Now, you can work with the data as a Ruby hash
puts parsed_data['name']
puts parsed_data['age']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the JSON.parse method is used to convert the JSON string received from the API into a Ruby hash. This allows you to access and manipulate the data in a more convenient and structure way. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How and when to use .parse method?&lt;/strong&gt;&lt;br&gt;
You would use the .parse method when you have a string representation of a data, time, or other structure data, and you want to convert it into an object of the corresponding class. This is particularly useful when working with user input or data from external sources where the information is represented as strings. &lt;/p&gt;

</description>
      <category>beginners</category>
      <category>ruby</category>
    </item>
    <item>
      <title>The .gsub method</title>
      <dc:creator>Thieu Luu</dc:creator>
      <pubDate>Sat, 13 Jan 2024 02:49:38 +0000</pubDate>
      <link>https://dev.to/tluu5/the-gsub-method-a34</link>
      <guid>https://dev.to/tluu5/the-gsub-method-a34</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is .gsub method?&lt;/strong&gt;&lt;br&gt;
The .gsub method is used for string manipulation, specifically for replacing occurrences of a specified pattern with another string. The .gsub stands for Global Substitution. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;original_string = "Hello, world! Hello, Ruby!"

# Using .gsub to replace "Hello" with "Hi"
modified_string = original_string.gsub("Hello", "Hi")

puts modified_string
# Output: Hi, world! Hi, Ruby!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The gsub method takes two arguments:&lt;br&gt;
1) The substring or regular expression you want to search for.&lt;br&gt;
2) The replacement string that will replace the matched patterns.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How and when to use .gsub method?&lt;/strong&gt;&lt;br&gt;
You might use the .gsub method when you need to perform global replacement within a string. Common use cases include cleaning up or transforming data, modifying text content, or implementing search and replace functionality.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>ruby</category>
    </item>
    <item>
      <title>The .concat method</title>
      <dc:creator>Thieu Luu</dc:creator>
      <pubDate>Sat, 13 Jan 2024 02:31:21 +0000</pubDate>
      <link>https://dev.to/tluu5/the-concat-method-lda</link>
      <guid>https://dev.to/tluu5/the-concat-method-lda</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is .concat method?&lt;/strong&gt;&lt;br&gt;
The .concat method is used to combine the elements of one array or string with another array or string. It's important to note that the original objects are modified in place.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array1 = [1, 2, 3]
array2 = [4, 5, 6]

# Using .concat to combine the elements of array1 and array2
array1.concat(array2)

puts array1 # Output: [1, 2, 3, 4, 5, 6]

string1 = "Hello, "
string2 = "world!"

# Using .concat to combine the strings
string1.concat(string2)

puts string1 # Output: Hello, world!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;*&lt;em&gt;How and when to use .concat method? *&lt;/em&gt;&lt;br&gt;
You would use the .concat method when you want to combine the elements of one array or string with another, and you prefer to modify the original object rather than creating a new one. This method is particularly useful when working with mutable objects like array and strings, where you want to update the existing data rather than creating a new object with the combined content. &lt;/p&gt;

</description>
      <category>beginners</category>
      <category>ruby</category>
    </item>
    <item>
      <title>The .new method</title>
      <dc:creator>Thieu Luu</dc:creator>
      <pubDate>Sat, 13 Jan 2024 02:13:55 +0000</pubDate>
      <link>https://dev.to/tluu5/the-new-method-312c</link>
      <guid>https://dev.to/tluu5/the-new-method-312c</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is the .new method?&lt;/strong&gt;&lt;br&gt;
.new method is a class method that is commonly used to create a new instance of a class. It is typically associated with class constructors and is used to instantiate object from a class. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Person
   attractive_accessor :name, :age

   def initialize(name, age)
      @name = name
      @age = age
   end
end

# Using .new to create a new instance of the Person class
person1 = Person.new("John", 30)

puts personal.name # Output: John
puts personal.age  # Output: 30
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the .new method is called on the 'Person' class to create a new instance of the class, and it calls the 'initialize' method to set the initial values for the instance variables ('name' and 'age' in the case).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How and when to use .new method?&lt;/strong&gt;&lt;br&gt;
You use the .new method when you want to create object of a particular class. This is a common practice in object-oriented programming where classes are used to model and structure code, and objects are instance of those classes that hold specific data and behavior. &lt;/p&gt;

</description>
      <category>beginners</category>
      <category>ruby</category>
    </item>
  </channel>
</rss>
