Skip to main content
replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

Several months ago, I asked Program to count vowelsProgram to count vowels, which was asking for a code review of a vowel counting function in implemented in Python.

Since I've been trying to learn Ruby, I decided to reimplement the entire program in it. I'm mainly looking for critiques on:

  • Naming conventions
  • Best practices for string iteration
  • do/end vs {}
  • Coding standards and best practices

Of course there are some slight changes in how I implemented this in ruby vs Python. The biggest being simply using a Hash since I couldn't find a suitable replacement for Python's tuples. On a unrelated side note, is there a replacement for Python's tuples in ruby?


def count_vowels(string)
    # Create a function that will receive a string. The
    # function will count each vowel in the string and
    # return a count of all the vowels, whether found or not,
    # each being a `key, value` in a Hash.
    vowels = {"a" => 0, "e" => 0, "i" => 0, "o" => 0, "u" => 0}
    string.each_char do |chr|
        if vowels.has_key?(chr)
            vowels[chr] += 1
        end
    end
    return vowels
end

Several months ago, I asked Program to count vowels, which was asking for a code review of a vowel counting function in implemented in Python.

Since I've been trying to learn Ruby, I decided to reimplement the entire program in it. I'm mainly looking for critiques on:

  • Naming conventions
  • Best practices for string iteration
  • do/end vs {}
  • Coding standards and best practices

Of course there are some slight changes in how I implemented this in ruby vs Python. The biggest being simply using a Hash since I couldn't find a suitable replacement for Python's tuples. On a unrelated side note, is there a replacement for Python's tuples in ruby?


def count_vowels(string)
    # Create a function that will receive a string. The
    # function will count each vowel in the string and
    # return a count of all the vowels, whether found or not,
    # each being a `key, value` in a Hash.
    vowels = {"a" => 0, "e" => 0, "i" => 0, "o" => 0, "u" => 0}
    string.each_char do |chr|
        if vowels.has_key?(chr)
            vowels[chr] += 1
        end
    end
    return vowels
end

Several months ago, I asked Program to count vowels, which was asking for a code review of a vowel counting function in implemented in Python.

Since I've been trying to learn Ruby, I decided to reimplement the entire program in it. I'm mainly looking for critiques on:

  • Naming conventions
  • Best practices for string iteration
  • do/end vs {}
  • Coding standards and best practices

Of course there are some slight changes in how I implemented this in ruby vs Python. The biggest being simply using a Hash since I couldn't find a suitable replacement for Python's tuples. On a unrelated side note, is there a replacement for Python's tuples in ruby?


def count_vowels(string)
    # Create a function that will receive a string. The
    # function will count each vowel in the string and
    # return a count of all the vowels, whether found or not,
    # each being a `key, value` in a Hash.
    vowels = {"a" => 0, "e" => 0, "i" => 0, "o" => 0, "u" => 0}
    string.each_char do |chr|
        if vowels.has_key?(chr)
            vowels[chr] += 1
        end
    end
    return vowels
end
edited body
Source Link
Chris
  • 1k
  • 8
  • 21

Several months ago, I asked Program to count vowels, which was asking for a code review of a vowel counting function in implemented in Python.

Since I've been trying to learn Ruby, I decided to reimplement the entire program in it. I'm mainly looking for critequescritiques on:

  • Naming conventions
  • Best practices for string iteration
  • do/end vs {}
  • Coding standards and best practices

Of course there are some slight changes in how I implemented this in ruby vs Python. The biggest being simply using a Hash since I couldn't find a suitable replacement for Python's tuples. On a unrelated side note, is there a replacement for Python's tuples in ruby?


def count_vowels(string)
    # Create a function that will receive a string. The
    # function will count each vowel in the string and
    # return a count of all the vowels, whether found or not,
    # each being a `key, value` in a Hash.
    vowels = {"a" => 0, "e" => 0, "i" => 0, "o" => 0, "u" => 0}
    string.each_char do |chr|
        if vowels.has_key?(chr)
            vowels[chr] += 1
        end
    end
    return vowels
end

Several months ago, I asked Program to count vowels, which was asking for a code review of a vowel counting function in implemented in Python.

Since I've been trying to learn Ruby, I decided to reimplement the entire program in it. I'm mainly looking for criteques on:

  • Naming conventions
  • Best practices for string iteration
  • do/end vs {}
  • Coding standards and best practices

Of course there are some slight changes in how I implemented this in ruby vs Python. The biggest being simply using a Hash since I couldn't find a suitable replacement for Python's tuples. On a unrelated side note, is there a replacement for Python's tuples in ruby?


def count_vowels(string)
    # Create a function that will receive a string. The
    # function will count each vowel in the string and
    # return a count of all the vowels, whether found or not,
    # each being a `key, value` in a Hash.
    vowels = {"a" => 0, "e" => 0, "i" => 0, "o" => 0, "u" => 0}
    string.each_char do |chr|
        if vowels.has_key?(chr)
            vowels[chr] += 1
        end
    end
    return vowels
end

Several months ago, I asked Program to count vowels, which was asking for a code review of a vowel counting function in implemented in Python.

Since I've been trying to learn Ruby, I decided to reimplement the entire program in it. I'm mainly looking for critiques on:

  • Naming conventions
  • Best practices for string iteration
  • do/end vs {}
  • Coding standards and best practices

Of course there are some slight changes in how I implemented this in ruby vs Python. The biggest being simply using a Hash since I couldn't find a suitable replacement for Python's tuples. On a unrelated side note, is there a replacement for Python's tuples in ruby?


def count_vowels(string)
    # Create a function that will receive a string. The
    # function will count each vowel in the string and
    # return a count of all the vowels, whether found or not,
    # each being a `key, value` in a Hash.
    vowels = {"a" => 0, "e" => 0, "i" => 0, "o" => 0, "u" => 0}
    string.each_char do |chr|
        if vowels.has_key?(chr)
            vowels[chr] += 1
        end
    end
    return vowels
end
added 11 characters in body
Source Link
Chris
  • 1k
  • 8
  • 21

Several months ago, I asked Program to count vowels, which was asking for a code review of a vowel counting function in implemented in Python.

Since I've been trying to learn Ruby, I decided to reimplement the entire program in it. I'm mainly looking for criteques on:

  • Naming conventions
  • Best practices for string iteration
  • do/end vs {}
  • Coding standards and best practices

OverOf course there are some slight changes in how I implemented this in ruby vs Python. The biggest being simply using a Hash since I couldn't find a suitable replacement for Python's tuples. On a unrelated side note, is there a replacement for Python's tuples in ruby?


def count_vowels(string)
    # Create a function that will receive a string. The
    # function will count each vowel in the string and
    # return a count of all the vowels, whether found or not,
    # each being a `key, value` in a Hash.
    vowels = {"a" => 0, "e" => 0, "i" => 0, "o" => 0, "u" => 0}
    string.each_char do |chr|
        if vowels.has_key?(chr)
            vowels[chr] += 1
        end
    end
    return vowels
end

Several months ago, I asked Program to count vowels, which was asking for a code review of a vowel counting function in implemented in Python.

Since I've been trying to learn Ruby, I decided to reimplement the entire program in it. I'm mainly looking for:

  • Naming conventions
  • Best practices for string iteration
  • do/end vs {}
  • Coding standards and best practices

Over course there are some slight changes in how I implemented this in ruby vs Python. The biggest being simply using a Hash since I couldn't find a suitable replacement for Python's tuples. On a unrelated side note, is there a replacement for Python's tuples in ruby?


def count_vowels(string)
    # Create a function that will receive a string. The
    # function will count each vowel in the string and
    # return a count of all the vowels, whether found or not,
    # each being a `key, value` in a Hash.
    vowels = {"a" => 0, "e" => 0, "i" => 0, "o" => 0, "u" => 0}
    string.each_char do |chr|
        if vowels.has_key?(chr)
            vowels[chr] += 1
        end
    end
    return vowels
end

Several months ago, I asked Program to count vowels, which was asking for a code review of a vowel counting function in implemented in Python.

Since I've been trying to learn Ruby, I decided to reimplement the entire program in it. I'm mainly looking for criteques on:

  • Naming conventions
  • Best practices for string iteration
  • do/end vs {}
  • Coding standards and best practices

Of course there are some slight changes in how I implemented this in ruby vs Python. The biggest being simply using a Hash since I couldn't find a suitable replacement for Python's tuples. On a unrelated side note, is there a replacement for Python's tuples in ruby?


def count_vowels(string)
    # Create a function that will receive a string. The
    # function will count each vowel in the string and
    # return a count of all the vowels, whether found or not,
    # each being a `key, value` in a Hash.
    vowels = {"a" => 0, "e" => 0, "i" => 0, "o" => 0, "u" => 0}
    string.each_char do |chr|
        if vowels.has_key?(chr)
            vowels[chr] += 1
        end
    end
    return vowels
end
Source Link
Chris
  • 1k
  • 8
  • 21
Loading