Skip to content

Conversation

@Slavunderkind
Copy link
Owner

No description provided.

letters_weight[2] = %w(d g)
letters_weight[3] = %w(b c m p)
letters_weight[4] = %w(f h v w y)
letters_weight[5] = ['k']
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's okay to %w(k) for consistency.


def initialize
@n = gets.to_i
@dictionary = @n.times.each_with_object([]) { |_, result| result << gets.chomp }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Define a local n variable here. You don't need instance one.

@dictionary = Array.new(n) { gets.chomp }

end

def init_letters_weight
letters_weight = {}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can define a hash to return at once:

def init_letters_weight
  {
    1 => %w(e a i o n r t l s u),
    2 => %w(d g),
    ...
  }
end

end

def matching?(word)
word.each_char do |char|
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One way to refactor is to use an any? block for this method.

end

obj = Scrabble.new
obj.start
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can say:

puts obj.find_all_words

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant