Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.6.0] Refine features and add dynamic type checkers #19

Merged
merged 5 commits into from
Apr 17, 2020

Conversation

serradura
Copy link
Owner

@serradura serradura commented Apr 13, 2020

Refine the behavior of Kind.of()/Kind.is(), allowing the creation of type checkers dynamically.

Kind.of(User, user) # <User ...>
Kind.of(User, {})   # Kind::Error ({} expected to be a kind of User)

Kind.of(Hash, {})   # {}
Kind.of(Hash, user) # Kind::Error (<User ...> expected to be a kind of Hash)

# ---

kind_of_user = Kind.of(User)

kind_of_user.or_nil({}) # nil

kind_of_user.instance?({})   # false
kind_of_user.instance?(User) # true

kind_of_user.class?(Hash)  # false
kind_of_user.class?(User)  # true

# Create type checkers dynamically is cheap
# because of a singleton object is created to be available for use.

kind_of_user.object_id == Kind.of(User).object_id # true

# --------------------------------------------- #
# Kind.is() can be used to check a class/module #
# --------------------------------------------- #

class Admin < User
end

Kind.is(Admin, User) # true

Adds Kind::Empty

A bunch of frozen values as constants, that could be used as a default value.

  • Kind::Empty::SET
  • Kind::Empty::HASH
  • Kind::Empty::ARRAY
  • Kind::Empty::STRING

Improve a lot of other things like: type checker features and optimizations.

Read the readme changes to know them! 😅

@serradura serradura added the enhancement New feature or request label Apr 13, 2020
@serradura serradura self-assigned this Apr 13, 2020
@serradura serradura changed the title [1.6.0] Add dynamic type checkers and refine features [1.6.0] Refine features and add dynamic type checkers Apr 13, 2020
@serradura serradura force-pushed the add_dynamic_type_checkers branch 3 times, most recently from ba390a9 to b6abeac Compare April 17, 2020 03:30
@serradura serradura added this to the v1.x milestone Apr 17, 2020
@serradura serradura marked this pull request as ready for review April 17, 2020 04:03
@serradura serradura merged commit b0433ab into master Apr 17, 2020
@serradura serradura deleted the add_dynamic_type_checkers branch April 17, 2020 04:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant