Module: Perquackey::Anagrams

Defined in:
ext/perquackey/anagrams.c

Instance Method Summary collapse

Instance Method Details

#each_anagram(letters_value) ⇒ Object

call-seq:

each_anagram(letters) { |anagram| ... } -> nil


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'ext/perquackey/anagrams.c', line 45

static VALUE Anagrams_each_anagram(VALUE self, VALUE letters_value) {
  rb_io_t *stream;
  char     word[MAX_LENGTH];
  char    *letters = RSTRING_PTR(letters_value);

  GetOpenFile(self, stream);

  while (fgets(word, sizeof(word), rb_io_stdio_file(stream)) != NULL) {
    chop(word);

    if (anagram_p(letters, word)) {
      rb_yield(rb_str_new2(word));
    }
  }

  return Qnil;
}